Hi, I am a newbie in KL03. The objective of my code is to run in VLPR and VLPW depending on an external signal. In both modes the LPTMR, ADC and the LPUART should be fully functional. I have checked the power demo of KL03 in which you are able to select among different power modes and the wake up source, everything works fine.
Using the KDS and Processor Expert I tried to configure the two modes of operation (VLPR and VLPW) and 1 type of callback, and even if I ask the PE to initialize the system in VLPW, it initializes in VLPR and is not able to get into the VLPW with the instruction
POWER_SYS_SetMode(kPowerManagerVlpw, PowerManagerPolicyAgreement);
While debugging, when I run this SetMode instruction, I see that in fsl_power_manager.c the variable mode is not set to kPowerManagerVlpw but to kPowerManagerVlpr. I force mode to be kPowerManagerVlpw in the debugger, and it works for a while. The KL03 executes the code:
case kPowerManagerVlpw:
halModeConfig.powerModeName = kPowerModeVlpw;
break;
and in fsl_smc_hal.c it executes the code:
case kPowerModeVlpw:
/* Clear the SLEEPDEEP bit to disable deep sleep mode - enter wait mode*/
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
Until it gets to wfi.
What should I do to avoid setting the mode to kPowerManagerVlpw using the debugger (which is not realistic)? Running in VLPR, I use the following instruction to get to VLPW:
// Errata 8068 fix
SIM->SCGC6 |=SIM_SCGC6_RTC_MASK; // enable clock to RTC
RTC->TSR = 0x00; // dummy write to RTC TSR per errata 8068
SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK; // disable clock to RTC
ret_power=POWER_SYS_SetMode(kPowerManagerVlpw, kPowerManagerPolicyAgreement);
After searching for this in the NXP Community, I decided to manage the transitions between power modes with the registers. The following is the code that I adapted from NXP community sources:
void goToVLPW(){
int a;
int clk;
update_clock(CLOCK_VLPR);
CLOCK_SYS_GetFreq(kCoreClock, &freq);
gpioEnableWakeUp();
// Errata 8068 fix: https://community.nxp.com/thread/350259
SIM->SCGC6 |=SIM_SCGC6_RTC_MASK; // enable clock to RTC
RTC->TSR = 0x00; // dummy write to RTC TSR per errata 8068
SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK; // disable clock to RTC
power_mode_status = SMC_PMSTAT; //Pag. 206 RefMan
if (power_mode_status == 4){
//It is in VLPR
SCB_SCR &=~ SCB_SCR_SLEEPDEEP_MASK; //SLEEPDEEP cleared; Pag. 213 RefMan
SCB_SCR |= (SCB_SCR_SLEEPONEXIT_MASK); //Enter Sleep-On-Exit mode set
dummyread = SCB_SCR;
(void)dummyread;
__asm("WFI"); //Enter VLPW
}
power_mode_status = SMC_PMSTAT; //Pag. 206 RefMan
}
How is it possible to work with the ADC, LPTMR and LPUART when operating in VLPW? Is there a way to check if I am really entering into that mode (without measuring the current consumption in my FRDM-KL03 board)? My interrupt will be based on a GPIO input.
I really appreciate any help you can provide.
Best,
Andy