KL24z Wake up from VLLS3

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

KL24z Wake up from VLLS3

3,100 Views
mikeconover
Contributor II

I am able to put the KL24Z processor into deep sleep with no problems. However, I am having trouble waking up from deep sleep. I am trying to use the low power timer to wake up every minute from deep sleep. Below is my code to get into VLLS3. How do you wakeup from deep sleep???

SMC_PMPROT = SMC_PMPROT_AVLLS_MASK;

SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK ;

SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4) ;

SMC_STOPCTRL = SMC_STOPCTRL_VLLSM(3);

SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;

asm("WFI");

Thanks a lot,

Mike

28 Replies

2,077 Views
adriancano
NXP Employee
NXP Employee

Hi,

Are you using MQX lite for your project? are you enabling the interrupt of the LLWU?

If yes you can use the Processor Expert method Cpu_SetOperationMode(DOM_STOP,NULL,NULL); to enter into VLLS3 mode.

Thank you for the information,
Adrian Sanchez Cano
Technical Support Engineer

0 Kudos

2,077 Views
mikeconover
Contributor II

Adrian,

Yes, I am using MQX lite for my project.

When I tried using Cpu_SetOperationMode(DOM_STOP,NULL,NULL); to put the processor into deep sleep, it seemed like it was never going into VLLS3 mode. I tried pretty much every different low power setting in processor expert and nothing seemed to help. The processor was always pulling a couple mA when it would go into sleep. The code in my first post is what I used to get around that. With that I am getting the power down to 6 to 7uA. 

That being said, in processor expert I am enabling the LLWU. Does this only get enabled when using  Cpu_SetOperationMode(DOM_STOP,NULL,NULL);???

Here is the other thread that I posted a few weeks ago.

low power mode for KL24z

0 Kudos

2,076 Views
adriancano
NXP Employee
NXP Employee

Hi,

The code you posted above is the same that processor expert writes for the Cpu_SetOperationMode(DOM_STOP,NULL,NULL) but if your code is working better for you you can use it instead. The method Cpu_SetOperationMode only clears the LLWU flags and set the appropriate registers to enter VLLS modes. The post in the MCUOnEclipse blog is really good an give you some hints and tips to have lower current.


I did a project to enter to VLLS2 mode and found some strange behavior of the LLWU when using MQX lite. I recommend you the next tests:


  • Ensure that the LLWU interrupt is enabled, this will create an event called Cpu_OnLLSWakeUpINT in the Events.c file. This method is a callback that is called when the LLWU interrupt is serviced. You can see the LLWU interrupt in the Cpu.c file with the name Cpu_INT_LLWInterrupt. You can see that the LLWU is being enabled in the PE_low_level_init in the Cpu.c file with something like this NVICISER0 |= NVIC_ISER_SETENA(IRQ number in hex);

    llwu interrupt.png

      Write a code inside the Cpu_OnLLSWakeUpINT callback to check if the LLWU interrupt is being services and know if the device is being waken up. When the reset occurs the LLWU ISR is the first think called  after the global interrupts are enabled. This is to check if the LLWU ISR is serviced. You can turn on a led there with something like this:

   

SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;

PORTC_PCR8 = PORT_PCR_MUX(0x01);

GPIOC_PDDR |= 1<<8;

GPIOC_PSOR |= 1<<8;


    You need to configure the clock because are not configured at this point.

    :smileyalert: Remember that is you are debugging when entering VLLS mode the debug will be disconnected. Because of this the recommended procedure is to disconnect and connect again the board to ensure it is not trying to restart the          communication.

Let me know your results.


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

2,076 Views
mikeconover
Contributor II

Adrian,

Thanks for your reply. I went back and replaced the code in my first post with Cpu_SetOperationMode(DOM_STOP,NULL,NULL) and it seems to be working now. I am not sure what was going on in the past when I was using this command.


I made all the changes you suggested above and I am still not able to come out of VLLS3. :smileycry: I made sure that the LLWU interrupt is enabled. I wrote code inside the Cpu_OnLLSWakeUpINT callback to check if the LLWU interrupt is being serviced. It doesn't look like it is though. I am toggling an LED in this callback function and never see it. It looks like something is happening when the low power timer expires though. After it expires, I see the processor start drawing 2mA of current, but nothing seems to be turning on and working.


When you say I need to configure the clock because they are not configured at this point. Will Cpu_SetClockConfiguration(2); work or I need a different command to setup the clock. I put Cpu_SetClockConfiguration(2); in the Cpu_OnLLSWakeUpINT callback. Is that correct or do I need to put it somewhere else??


Yeah, I know that the debugger will get disconnected. I have tried getting out of VLLS3 well over 1000 times with no success. lol

Just to give you a little more insight into my application. I am using clock configuration 2 as my normal running clock and I am blinking LED's and talking to serial ports and i2c ports and a bunch of other stuff. Then, I have a low power clock configuration that I set before going into VLLS3 mode.

Thanks for the help,

Mike

0 Kudos

2,076 Views
mjbcswitzerland
Specialist V

Mike

On the FRDM-KL25Z I have about 2uA current consumption in VLLS3 mode and can wake it from any LLWU pin or LLWU module (such as LPTMR), whereby the wakeup is via reset as discussed previously.

If you have a FRDM-KL25Z board you can load the attached binary to it and command any low power mode in the "administator" menu. It can wake from LLS to normal operation mode or from VLLS3 via reset by connecting J1-pin 9 to GND. This is the easiest way to test the operation but the same happens if I configure for LPTRM (after a fixed delay of course).

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market


0 Kudos

2,078 Views
mikeconover
Contributor II

I have been reading through posts all day today trying to figure out how to do this. Is the below statement true??? :smileycry:

If you go into VLLSx mode, a wake up event will simple cause a reset of the device and the MQX application will simple start and run as if a Power On Reset occurred.

0 Kudos

2,078 Views
yasuhikokoumoto
Senior Contributor I

Hi Mike,

I wrote the wake-up program from VLLS3 by TPTMR on FRDM-KL25Z baremetal environment.

#define  LLWU_irq_no            7 #define LPTMR_USE_LPOCLK        1 #define LLWU_LPTMR_ME          0x01

int main (void) {     DisableInterrupts;

    enable_irq(LLWU_irq_no);     LLWU_ME = LLWU_LPTMR_ME;  //Set up more modules to wakeup up

    SIM_SCGC5 |= SIM_SCGC5_LPTMR_MASK;     LPTMR0_PSR = ( LPTMR_PSR_PRESCALE(0) // 0000 is div 2                 | LPTMR_PSR_PBYP_MASK  // LPO feeds directly to LPT                 | LPTMR_PSR_PCS(LPTMR_USE_LPOCLK)) ; // use the choice of clock               LPTMR0_CMR = LPTMR_CMR_COMPARE(1000);  //Set compare value (100ms)

    LPTMR0_CSR =(  LPTMR_CSR_TCF_MASK  // Clear any pending interrupt                 | LPTMR_CSR_TIE_MASK  // LPT interrupt enabled                 | LPTMR_CSR_TPS(0)    //TMR pin select                 |!LPTMR_CSR_TPP_MASK  //TMR Pin polarity                 |!LPTMR_CSR_TFC_MASK  // Timer Free running counter is reset                                         //  whenever TMR counter equals compare                 |!LPTMR_CSR_TMS_MASK  //LPTMR0 as Timer                 );

    LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;  //Turn on LPT and start counting         SMC_PMPROT = SMC_PMPROT_AVLLS_MASK;     SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK ;     SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4) ;     SMC_STOPCTRL = SMC_STOPCTRL_VLLSM(3);     SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;     asm("WFI");

}

The waking up initiates from the reset state. The following is the console message.

pastedImage_4.png

Best regards,

Yasuhiko Koumoto.

0 Kudos

2,078 Views
mikeconover
Contributor II

Yasuhiko,

Thanks for the reply with some code. So, in your code do you have an LLWU interrupt routine that gets called when the LPTMR expires?

Thanks,

Mike

0 Kudos

2,078 Views
yasuhikokoumoto
Senior Contributor I

Hi Mike,

regarding the my sample code, when enable_irq(LLWU_irq_no) was executed, something was wrong. I should remove enable_irq(LLWU_irq_no) because the cpu was hanged up after waked up. If I removed enable_irq(LLWU_irq_no) , the CPU repeated entering VLLS3 and exiting from it. Can anyone explan the bejavior?


Best regards,

Yasuhiko Koumoto.

0 Kudos

2,078 Views
adriancano
NXP Employee
NXP Employee

Hi,

In the LLWU ISR you need to check the flags to know what was the source of the wake up. When a module, like the LPTMR, is used to wake up the device you need to erase the module flag with. You need to write something like this in the LLWU ISR:

  if (LLWU_F3 & LLWU_F3_MWUF0_MASK) {       //check if the LPTMR that is associetes with the Wake UP module 0 was the wake up source

         SIM_SCGC5 |= SIM_SCGC5_LPTMR_MASK;

         LPTMR0_CSR |=  LPTMR_CSR_TCF_MASK;   // write 1 to TCF to clear the LPT timer compare flag

         LPTMR0_CSR = ( LPTMR_CSR_TEN_MASK | LPTMR_CSR_TIE_MASK | LPTMR_CSR_TCF_MASK  );

Hope this helps.

0 Kudos

2,078 Views
yasuhikokoumoto
Senior Contributor I

Hi Adrian,

I tried the advice but it was helpless. LLWU ISR seemed not to be called by my sample code. Therefore LLWU_F3 flag was not cleared, making entering VLLS3 mode failed after the 2nd time. My conclusion is that the enable_irq(LLWU_irq_no) had not been needed. If the enable_irq(LLWU_irq_no) would be added, the description to clear the LLWU_F3 flag which were mentioned in your post would be needed before entering VLLS3 mode.


Best regards,

Yasuhiko Koumoto.

2,078 Views
mjbcswitzerland
Specialist V

Hi Yiasuhiko


If you enter VLLS3 your interrupt handler will not be called.


However the interrupt is pending after the processor exits reset. This means that the flag should be reset before enabling interrupts again otherwise it will be called then.

Also, don't forget that LLWU peripherals and I/O are isolated (still in LLWU mode) when the processor restarts and you need to set then back to run mode before they can be used normally again - see an overview of the most important details at µTasker LLWU Support


Regards


Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

2,078 Views
mikeconover
Contributor II

Mark,

When you say the flag should be reset before enabling interrupts again otherwise it will be called then. Where should this be done?

-Mike

0 Kudos

2,077 Views
mjbcswitzerland
Specialist V

Mike

>>When you say the flag should be reset before enabling interrupts again otherwise it will be called then. Where should this be done?

Anywhere suitable before enabling the LLWU interrupt in the NVIC.

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

2,078 Views
mikeconover
Contributor II

Mark,

One other question. When you said "When waking from VLLS3 via a wakeup source this can be detected by the RCM_SRS0_WAKEUP bit in RCM_SRS0" where would I put this logic to check the wakeup source? Would I put it in the void Cpu_OnLLSWakeUpINT(void) callback? Cpu_OnLLSWakeUpINT(void) doesn't seem to be getting called after waking up form VLLS3.

Thanks,

Mike

0 Kudos

2,078 Views
mjbcswitzerland
Specialist V

Mike

You will NEVER have an interrupt callback from VLLS3 mode (you will only get it from LLS mode, as its name suggests).

Place the following in your startup code, immediately after the watchdog is configured/disabled (check your HW headers for the names):

PMC_REGSC = PMC_REGSC_ACKISO;

In fact I would expect it to be there already in any framework with VLLSx support otherwise the operation has probably never actually been used/tested apart from for a simple reset button demonstration.

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

2,077 Views
mikeconover
Contributor II

Mark,

Thanks for the reply. So even after I come out of VLLS3 and the processor is reset, Cpu_OnLLSWakeUpINT(void) callback will never get called?

Thanks,

Mike

0 Kudos

2,077 Views
mjbcswitzerland
Specialist V

Mike

>>So even after I come out of VLLS3 and the processor is reset, Cpu_OnLLSWakeUpINT(void) callback will never get called?

That is the case and why the calback is named OnLSS and not OnVLLSx because there is NEVER an interrupt on VLLSx wakeup.

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

2,077 Views
mikeconover
Contributor II

Mark,

Thanks for the reply. So, where would I put my code to switch clock configurations and get the processor back up and running? Right now, when the low power timer expires, something seems to happen, but it doesn't look like a reset.

Thanks,

Mike

0 Kudos

2,083 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

to cleat LLWU_F3 flash and to clear NVIC interrupt pending are different things. LLWU_F3 flag would be cleared at the new LPTMR setting but then pending NVIC interrupt is not cleared. So if the LLWU interrupt was not enabled, we didn't care the NVIC interrupt pending. To wake up from LLVSx we only set LLWU_ME. To enable LLWU interrupt is not necessary. This is the result of my experiment by using FRDM-KL25Z.

By the way, I cannot understand the following statement in the "VLLSx modes' paragraph of the link shown by you.


"The isolated peripherals and I/Os are then acknowledged in the power management controller so that they are released back to their RUN modes. "

What does the "then" mean?

Best regards,

Yasuhiko Koumoto.

0 Kudos