Can't wake up from STOP with LPTMR

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

Can't wake up from STOP with LPTMR

1,006 Views
bcstewart
Contributor III

Processor: K22FN512 64-pin

Board:  Custom and FRDM-K22F

IDE:  KDS and Processor Expert

ErichS

Problem is I am unable to wake from LPTMR when in STOP MODE.

It works fine if I use the function

Cpu_SetOperationMode(DOM_SLEEP, NULL, NULL);

or

Cpu_SetOperationMode(DOM_WAIT, NULL, NULL);

with DOM_STOP, it never wakes.

Clock source is 32KHz crystal (confirmed it always oscillates, even in stop)

Here are the settings for the CPU

pastedImage_1.png

I have set up the LLWU as well, but the interrupt is never called (even in SLEEP or WAIT)

pastedImage_3.png

This interrupt function gets called in DOM_SLEEP or DOM_WAIT after the LPTMR0 completes the count.

PE_ISR(Wakeup_Timer)

{
    LPTMR_PDD_ClearInterruptFlag(LPTMR0_DEVICE);

}

And here is the main routine that blinks LED 10 times and goes to LP mode.

  for(;;){
  /*
 * blink led 10 times
 */
  while(i<10){
  HB_LED_ON;
  WAIT1_Waitms(200);
  HB_LED_OFF;
  WAIT1_Waitms(200);
  i++;
  }
  i=0;

  /*
   * go into low power mode
  */

  LPTMR0_CSR |= 1;  //enable timer
  Cpu_SetOperationMode(DOM_STOP, NULL, NULL);//works if use DOM_WAIT or DOM_SLEEP
  LPTMR0_CSR &= ~1; //disable timer

}

Thanks for your help.

Labels (1)
0 Kudos
3 Replies

618 Views
mjbcswitzerland
Specialist V

Hi Brad

Which STOP mode is it that you are trying to use? Is it STOP or VLLS3?
Note that STOP (and VLPS etc.) are not low leakage modes and so won't be woken by the LLWU module since it is not operational in these.
LLS and VLLS modes will be woken by the LLWU unit.

This means that the 'standard' LPTMR interrupt will return you back to RUN mode from STOP modes and can wake from LLS modes via the wake up unit.

Beware that these things can't really be tested with a debugger connected so always load and power cycle the board before doing tests to be sure.

I have a attached a binary for the FRDM-K22F board so that you can get a feel for it. In the program I have configured a wake-up on SW2 (pressing it when in a LLS mode can wake up) and also on the LPTMR. The low power timer is clocked from the 32kHz RTC crystal (to match what I think you need) and it interrupts every 5s. When it interrupts it prints some text to inform from which power state it was interrupted in and toggles the RED LED- The green LED toggles faster (at 2.5Hz, driven from the SYSTICK instead).

Default is for the processor to be in WAIT mode but you can change this in the "Admin" menu on the VCOM interface at 115200 to check behavior in all K22 power modes.

Here is the command line interface where I show STOP, LLS3 and VLLS3 modes being entered, whereby the STOP mode will not retained after a LPTMR interrupt (to move back to WAIT mode hold SW3 down when the LPTMR message appears). You will see that the behavior in these modes is as theoretically expected:
- STOP mode freezes the SYSTICK operation but not the LPTMR
- LLS3 freezes SYSTICK but not LPTMR - LPTMR wakeup returns to RUN mode (and the handler sets itself to WAIT again). SW2 can also wake if pressed before the LPTMR interrupt arrives.
- VLLS3 is similar to LLS3 apart from the fact that it recovers via a reset.

Hello, world... FRDM-K22F [External]
Static memory = 0x00000720
OS Heap use = 0x0219 from 0x6000
Initial stack margin 0x0000978c
WOKEN - restoring WAIT mode
LPTMR int. from 1 = WAIT      <--- initially the system is using WAIT mode
LPTMR int. from 1 = WAIT

Serial number: 00             <---- enteer command line menu with ENTER key
Software version V1.4.012
Device identification: KINETIS

     Main menu
===================
1              Configure LAN interface
2              Configure serial interface
3              Go to I/O menu
4              Go to administration menu
5              Go to overview/statistics menu
6              Go to USB menu
7              Go to I2C menu
8              Go to utFAT disk interface
9              FTP/TELNET commands
a              CAN commands
help           Display menu specific help
quit           Leave command mode
4                                     <--- move to Admin menu with 4 + ENTER


   Admin. menu
===================
up               go to main menu
show_config      Show configuration
save             Save configuration to FLASH
reject           Reset non-saved changes
restore          Restore factory settings
show_time        Display date/time
set_time         Set time hh:mm:ss
set_date         Set Date dd:mm:yyyy
show_alarm       Display alarm d/t
set_alarm        Set alarm (date)(+)[time]
del_alarm        Delete alarm
show_lp          Show low power mode and options
set_lp           [option] Set low power mode
reset            Reset device
last_rst         Reset cause
help             Display menu specific help
quit             Leave command mode
LPTMR int. from 1 = WAIT
show_lp                            <------- show the power modes supported by the K22
0 = RUN
1 = WAIT [active]
2 = STOP
3 = VLPR
4 = VLPW
5 = VLPS
6 = LLS2
7 = LLS3
8 = VLLS0
9 = VLLS1
10 = VLLS2
11 = VLLS3

#LPTMR int. from 1 = WAIT        <---- LPTMR interrupt every 5s
LPTMR int. from 1 = WAIT
LPTMR int. from 1 = WAIT
set_lp 2                         <----- command to move to STOP mode
                                 <----- now the green LED stips flashing and no UART entry is possible
#LPTMR int. from 2 = STOP
LPTMR int. from 2 = STOP         <----- the LPTMT interrupt still works
LPTMR int. from 2 = STOP
LPTMR int. from 1 = WAIT         <----- here I have held SW3 so the interrupt sets back to WAIT mode
LPTMR int. from 1 = WAIT
LPTMR int. from 1 = WAIT
set_lp 7                         <---- back in WAIT mode the UART works again and the green LED blinks

#LPTMR int. from 6 = LLS2        <---- LLS2 is similar to STOP (no green LED)
WOKEN - restoring WAIT mode      <---- after max 5s the LPTMR wakes and retuns the system to WAIT mode
LPTMR int. from 1 = WAIT
LPTMR int. from 1 = WAIT
LPTMR int. from 1 = WAIT
set_lp 11                        <----- VLLS3 commaned here

#

Hello, world... FRDM-K22F [Wakeup]  <--- afer max. 5s the LPTMR wakes via RESET (note reset cause)
Static memory = 0x00000720
OS Heap use = 0x0219 from 0x6000
Initial stack margin 0x0000978c
LPTMR int. from 1 = WAIT
WOKEN - restoring WAIT mode
LPTMR int. from 1 = WAIT
LPTMR int. from 1 = WAIT

If you have specific questions I can explain more details and show you operational code for whatever cases are required.

Regards

Mark


uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html

0 Kudos

618 Views
bcstewart
Contributor III

Thanks Mark,

Thanks for the binary.

My client is using Processor Expert (PE) and FreeRTOS. I would like to move them to bare-metal (BM) or even uTasker (which I've used in the past and prefer it over FreeRTOS). 

I want to go to some low power stop mode, such as VLPS.  The few extra microamps is OK.

But for now, I need a PE/BM example.  

0 Kudos

618 Views
mjbcswitzerland
Specialist V

Hi Brad

VLPS is not a LLWU mode so you simply need a working LPTMR interrupt.
Also, if the WAIT mode works you can simply set
SMC_PMCTRL = (SMC_PMCTRL_RUNM_NORMAL | SMC_PMCTRL_STOPM_VLPS | SMC_PMCTRL_LPWUI);
and
SYSTEM_CONTROL_REGISTER |= SLEEPDEEP;

manually before calling the WAIT mode to get the same result.

I don't know how good PE generated code is in this respect but if you are not saving power make sure that you add code to its startup (which may be missing) to set SMC_PMPROT_AVLP in SMC_PMPROT register to enable the VLPS mode. Beware that the register is a "write-once" register and you need to power cycle the system if it has been written before to allow different modes to be used.
Again, I can imaging that PE generated code may not be suitable for dynamically changing systems where more that one mode is used so you may need to generate code for each mode you want to test, load it, power cycle, test and repeat for each to be sure.

Note that uTasker now incorporates FreeRTOS V9.0 for all devices so one can use uTasker OS, FreeRTOS OS or a mixture of both depending on which characteristics suit best. FreeRTOS and dynamic low power is however tricky. uTasker OS is optimised for dynamic low power operation which makes dynamic low power demos (and complete application) simple (as in binary file).

Good luck

Regards

Mark

P.S. PE generated code is simply copy-pasting some library code for you. If you have good library code that already does this (and works) I don't know that PE generated code has any real advantages. At the end of the day it is the reliable library code in operation that matters and not that it was configured in a GUI and generated.

0 Kudos