Wake up K22F from VLLS0 using RTC Alarm

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wake up K22F from VLLS0 using RTC Alarm

780 Views
gabriele_endriz
Contributor I

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?

Labels (1)
0 Kudos
1 Reply

628 Views
mjbcswitzerland
Specialist V


Hi

See some videos:
https://www.youtube.com/watch?v=kWNlsAoMly4&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q
https://www.youtube.com/watch?v=iZEMRiDmHzw&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q&index=5
https://www.youtube.com/watch?v=v4UnfcDiaE4&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q&index=7

You can get a working reference for low power operation on K22 (and most other parts) and Alarm wake-up in the free open source uTasker project at the links below.

Regards

Mark

Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html
i.MX RT project compatibility: http://www.utasker.com/iMX.html

Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html


uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

https://community.nxp.com/thread/512558
https://community.nxp.com/thread/352862
https://community.nxp.com/thread/498809

0 Kudos