AnsweredAssumed Answered

Wake up K22F from VLLS0 using RTC Alarm

Question asked by Gabriele Endrizzi on Oct 17, 2019
Latest reply on Oct 17, 2019 by Mark Butcher

Hi,

I must wake up periodically a MCU K22F from VLLS0 using the RTC Alarm. I have read on datasheets that is the solution that needs less power for a battery powered system. I use an external 32768Hz crystal for the RTC and the internal oscillator for the system. Now I tried to enter VLLS0 using this code:

 

vlls_config.subMode = kSMC_StopSub0;
vlls_config.enablePorDetectInVlls0 = true;
SMC_PreEnterStopModes();
SMC_SetPowerModeVlls(SMC, &vlls_config);
SMC_PostExitStopModes();

 

set RTC like this:

 

void set_RTC_Alarm(){
   /* Init RTC */
   RTC_GetDefaultConfig(&rtc_config);
   RTC_Init(RTC, &rtc_config);
   /* Select RTC clock source */   
   RTC_SetClockSource(RTC);

   /* RTC time counter has to be stopped before setting the date & time in the TSR register */
   RTC_StopTimer(RTC);
   RTC->TSR = 0; //reset RTC timer
   RTC->TAR = 10; //alarm set to 10 seconds

   RTC_StartTimer(RTC);

   /* Enable interrupt */
   EnableIRQ(RTC_IRQn);

   RTC_EnableInterrupts(RTC,kRTC_AlarmInterruptEnable);
}

 

and set LLWU like this:

 

void set_LLWU(){

   LLWU->PE1 = 0;
   LLWU->PE2 = 0;
   LLWU->PE3 = 0;
   LLWU->PE4 = 0;
   //LLWU->ME = LLWU_ME_WUME5_MASK; //rtc alarm
   LLWU_EnableInternalModuleInterruptWakup(LLWU,5U, true);
   EnableIRQ(LLWU_IRQn);
}

 

In this way the MCU goes to sleep with a current of 330uA respect to the 3.4 mA during the normal operation, but at the wake up from the alarm the MCU doesn't reset and restart from the instruction after the stop. I think it's not a real VLLS0.

 

If I use the following function taken from AN5403 to enter sleep:

 

void enter_vlls0(unsigned char PORPO_value )
{
   volatile unsigned int dummyread;
   /* Write to PMPROT to allow all possible power modes */
   SMC->PMPROT = SMC_PMPROT_AVLLS_MASK;
   /* Set the STOPM field to 0b100 for VLLS0 mode */
   SMC->PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
   SMC->PMCTRL |= SMC_PMCTRL_STOPM(0x4);
   /* set VLLSM = 0b00 */
   SMC->VLLSCTRL = (PORPO_value <<SMC_VLLSCTRL_PORPO_SHIFT)
   | SMC_VLLSCTRL_VLLSM(3);
   /*wait for write to complete to SMC before stopping core */
   dummyread = SMC->VLLSCTRL;
   dummyread++;
   /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
   SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
   __asm("WFI");
}

 

the MCU will consume only 50uA during deepsleep but after 10seconds I see a consumption increased to 2.4mA but MCU doesn't wake and stay stopped. I think this is a real VLLS0 but I am not able to wake up the MCU.

 

The IRG handler are those

 

void LLWU_IRQHandler(void){

   RTC_DisableInterrupts(RTC,kRTC_AlarmInterruptEnable);
   RTC_ClearStatusFlags(RTC,kRTC_AlarmFlag);
   //debug_printf("enter LLWU_IRQ\n");
   //printf("LLWU_IRQ\n");
   /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
   exception return operation might vector to incorrect interrupt */
   __DSB();
}

void RTC_IRQHandler(void){

   RTC_DisableInterrupts(RTC,kRTC_AlarmInterruptEnable);   
   RTC_ClearStatusFlags(RTC,kRTC_AlarmFlag);
   //debug_printf("enter LLWU_IRQ\n");
   //printf("RTC_IRQ\n");
   /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
   exception return operation might vector to incorrect interrupt */
   __DSB();
}

 

 

Where is the error?

Outcomes