Cannot Wake Up From LLS using LPTMR

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

Cannot Wake Up From LLS using LPTMR

Jump to solution
1,521 Views
petertwiss
Contributor III

Hello everyone,

 

Using Driver Suite 10.4 Ported to Keil, I am having trouble waking up from Sleep (LLS), using the Low Power Timer (LPTMR0) on a Kinetis KL15Z128xxx4.

 

I understand all that is needed to get it all to be set up in driver suite:

 

- under component inspector of the CPU, add LLS, and add LPTMR0 as a deivce for LLWU functionality.

- For Methods, add GetLLSWakeUpFlags(), and SetOperationMode()

- Make sure there is a Cpu_OnLLSWakeUpINT() function in the events list.

- Add a TimerUnit, which is LPTMR0, and add functions for setting offset and getting count, etc.

- I configure the LPTMR counter to be 1 sec ahead of the current grabbed Count (X + 1000), using a 1024 Hz Tick (~1ms)

- in main, call SetOperationMode(DOM_STOP, NULL, NULL); then I enter sleep.

- In the event Cpu_OnLLSWakeUpINT() call I check the flags as the following:

 

void Cpu_OnLLSWakeUpINT(void)

{

  /* Write your code here ... */

  (void)Cpu_SetOperationMode(DOM_RUN, PARAM_UNUSED_NULL, PARAM_UNUSED_NULL);

  if(Cpu_GetLLSWakeUpFlags() == LLWU_INT_MODULE0)

  WUT_LLWUFlag = true;

  else

  WUT_LLWUFlag = false;

}

 

**I then check the flag in main.

 

- When sleeping, I never wake up and enter PE_ISR(Cpu_INT_LLWInterrupt), I just d onot wake up.

 

As a basic test of the sleep/LLS, in main:

 

T0 = WUT_GetCounterValue(WUT_DevDrvPtr);

  (void)WUT_SetOffsetTicks(WUT_DevDrvPtr, (uint8_t)WUT_CHANNEL_ID, (WUT_TValueType)(T0 + (uint16_t)1000));

  (void)WUT_SetOperationMode(WUT_DevDrvPtr, DOM_STOP, PARAM_UNUSED_NULL, PARAM_UNUSED_NULL);

  (void)Cpu_SetOperationMode(DOM_STOP, PARAM_UNUSED_NULL, PARAM_UNUSED_NULL);

 

  sprintf(Buf, "\n\rHELLO WORLD\n");

  (void)UART_SendString(Buf, (uint16_t)14);

 

 

I never wake up and I am locked out of SWD.

Labels (1)
0 Kudos
1 Solution
982 Views
petertwiss
Contributor III

Hey Adrian,

Thanks for all of your help. I found my problem. It was that the system requires a bit of time before you can immediately start driving peripherals. I have a CPU_Delay_us() function using    __nop(); (Keil).

Adding about a 50usec delay just after the return from wake fixes my UART problem. I noticed in my jumbled data, the last character was actually correct, so I figured there is a system settle time coming out of sleep. I added it and then dropped the delay until the failure came back. Seems to be ~50usec is the sweet spot.

To help others who reference this:

//-----------main.c---------------

while(1)

{

       // SLEEP (LLS) FOR 1000ms:

       WUT_Sleep_ms((uint16_t)1000);

       // PRINT COUNTER, WHICH IS UPDATED EVERY TIME WE WAKE UP:

       sprintf(Buf, "\rTimer: 0x%x          ", Cntr);

       UART_SendString(Buf, 15);

       Cntr++;

}

// PLACED IN MY TIMER UNIT C-FILE, FOR IT IS IS CALLED: 'WUT.c'

void WUT_Sleep_ms(uint16_t Time_ms)

{

  uint16_t T0 = WUT_GetCounterValue(WUT_DevDrvPtr);

  (void)WUT_SetOffsetTicks(WUT_DevDrvPtr, (uint8_t)LPTMR0_CHANNEL0, (WUT_TValueType)(T0 + Time_ms));

  (void)CPU_SetOperationMode(DOM_STOP, NULL, NULL);

  Cpu_Delay_us(50);

}

View solution in original post

0 Kudos
9 Replies
983 Views
adriancano
NXP Employee
NXP Employee

Hi,

It is possible that the clock source you are for the timer is not enabled in low power modes, you need to ensure that the source clock for the LPTMR is enabled during LLS mode. I tested this using the LPO clock, which is enabled in all the low power modes.

lptmr_lpo.jpg


Hope this information can help you

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

0 Kudos
983 Views
petertwiss
Contributor III

Adrian,

See Reference Manual Page 132 / 755:

"Most peripherals are in state retention mode (with clocks

stopped), but OSC, LLWU,LPTMR, RTC, CMP, TSI can be used."

That statement is quite vague.

The clock I am using for this quick bring up is the default :

32.768 KHz w/ FFL @ 640 Multiplier ==> 20.97MHz.

I found this also in Reference Manual Page 373 / 755:

Entered whenever the MCU enters a Stop state. The power modes are chip specific. For power

mode assignments, see the chapter that describes how modules are configured and MCG behavior

during Stop recovery. Entering Stop mode, the FLL is disabled, and all MCG clock signals are static

except in the following case:

MCGPLLCLK is active in Normal Stop mode when PLLSTEN=1

MCGIRCLK is active in Normal Stop mode when all the following conditions become true:

• C1[IRCLKEN] = 1

• C1[IREFSTEN] = 1

**Also this on Page 112 / 755:

5.7.1 PMC 1-kHz LPO clock

The Power Management Controller (PMC) generates a 1-kHz clock that is enabled in all

modes of operation, including all low-power modes except VLLS0. This 1-kHz source is

commonly referred to as LPO clock or 1-kHz LPO clock.

**posting for others in the future..

Let me run PE again and implement a clock config setup (CONFIG_0 = default 20.97MHz, and CONFIG_1 = LPO use).

Can you send me your calls? I am new to implementing the clock configs. I  understand the PE conept of:

Oscillators ==> Clock Sources ==> Clock Settings, but I am a bit confused on the calling of SetOperationMode(), vs. SetClockConfiguration(). Seems like SetOperationsMode() doesn't cover all of the cases.

If you can please send your call on how you siwtches from 20.97 MHz, and into LPO, and the calls needed to update the LPTMR0 to get it back to align with a 1ms increment.

0 Kudos
983 Views
adriancano
NXP Employee
NXP Employee

Peter,

Attached you can find a KDS 2.0 project for a Kinetis KL25, the application is set to wake the MCU from LLS every 2 seconds using the LPTMR interrupt clocked by the LPO clock.


Hope this information can help you

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

0 Kudos
983 Views
petertwiss
Contributor III

Adrian,

When I drop this folder into my workspace, PE (Driver Suite 10.4) does not pull it into the workspace window. I have had this problem in the past, where I paste in a new PE project folder and Driver Suite doesn't add it into the project explorer.

How do I fix this?

Thanks,

-Peter

0 Kudos
983 Views
petertwiss
Contributor III

Hello Adrian,

I got it to work by setting the LPO as the main clock source for the LPTMR, and I can wake out of sleep now, but when I wake up my UART is all messed up. Before I go into sleep, my UART works perfectly.

I am not sure what happens to the CPU when the KL15 comes out of LLS, but it is not being configured back when awake.

I looked at your C-files, and you simply just call SetOperationMode() and just go to sleep, and when you wake up, you use the INT to clear some flags, and continue on.

Any idea?

0 Kudos
983 Views
adriancano
NXP Employee
NXP Employee

Hi,

Good to know you solved the Wake-up problem. In my example I am setting FEI mode and after exiting the LLS mode the core settings return to FEI mode. I am not sure but I assume you are using PEE mode and then enter to LLS mode, after exiting LLS mode the MCG will be in PBE mode, you need to ensure to return to the first configuration before the UART transmission.

Here the note form the reference manual:

note.jpg

Using PEx you can just call the method:

/*Moving to LLS mode*/

/*Waken up*/

Cpu_SetClockConfiguration(CPU_CLOCK_CONFIG_0)/*Moving to clock config 0...Now in PEE mode*/

/*Printf()*/

Hope this information can help you

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

0 Kudos
983 Views
petertwiss
Contributor III

Hey Adrian,

Thanks for all of your help. I found my problem. It was that the system requires a bit of time before you can immediately start driving peripherals. I have a CPU_Delay_us() function using    __nop(); (Keil).

Adding about a 50usec delay just after the return from wake fixes my UART problem. I noticed in my jumbled data, the last character was actually correct, so I figured there is a system settle time coming out of sleep. I added it and then dropped the delay until the failure came back. Seems to be ~50usec is the sweet spot.

To help others who reference this:

//-----------main.c---------------

while(1)

{

       // SLEEP (LLS) FOR 1000ms:

       WUT_Sleep_ms((uint16_t)1000);

       // PRINT COUNTER, WHICH IS UPDATED EVERY TIME WE WAKE UP:

       sprintf(Buf, "\rTimer: 0x%x          ", Cntr);

       UART_SendString(Buf, 15);

       Cntr++;

}

// PLACED IN MY TIMER UNIT C-FILE, FOR IT IS IS CALLED: 'WUT.c'

void WUT_Sleep_ms(uint16_t Time_ms)

{

  uint16_t T0 = WUT_GetCounterValue(WUT_DevDrvPtr);

  (void)WUT_SetOffsetTicks(WUT_DevDrvPtr, (uint8_t)LPTMR0_CHANNEL0, (WUT_TValueType)(T0 + Time_ms));

  (void)CPU_SetOperationMode(DOM_STOP, NULL, NULL);

  Cpu_Delay_us(50);

}

0 Kudos
983 Views
adriancano
NXP Employee
NXP Employee

Hi,

Good to know that know is working. This is a very tricky issue, you will find very useful this report from Mark Butcher:

Using Kinetis Low Power Stop Modes with unrestricted UART operation - a report


Hope this information can help you

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

0 Kudos
983 Views
petertwiss
Contributor III

Hey Adrian,

Thanks for the help, this can be closed,

-Peter

0 Kudos