I want to configure my FRDM-K22F to wakeup from VLLS2 mode each 1second using RTCn can someone help to configure this.
I download the SDK library but I didn't find such example
Thanks for help
Hello,
Thank you for your help :smileyhappy:
where can i find the code of this function : fnSetLowPowerMode(VLLS2_MODE);
I check the example power switch mode but it is very complicated, i need a simpler code on how to enter VLLS2 mode and wake up from this mode each 1s using RTC .
Nesrine
Hi
As mentioned, you can get a complete solution from the uTasker project on GitHub:
https://github.com/uTasker/uTasker-Kinetis
The routine fnSetLowPowerMode(VLLS2_MODE);
does (for your processor):
SMC_STOPCTRL = (SMC_STOPCTRL_VLLSM_VLLS2);
SMC_PMCTRL = (SMC_PMCTRL_RUNM_NORMAL | SMC_PMCTRL_STOPM_LLS);
SYSTEM_CONTROL_REGISTER |= SLEEPDEEP;
which prepares for the sleep mode, which is subsequently set using wfi instruction.
Regards
Mark
P.S. Note also that SMC_PMPROT has to be written to to enable the required low power mode(s) that will be used.
Since this is a write-once register it is best written during the board start-up so that all modes that may be required at any future time point are enabled.
Just add to Mark's good comments, you also can also refer to the power_mode_switch demo under the KSDK installation folder.
SDK_2.2_FRDM-K22F\boards\frdmk22f\demo_apps\power_mode_switch
This demo is to show how to switch to different power modes, and how to configure a wakeup source and wakeup the MCU from low power modes.
Regards
Daniel
Hi Nesrine
I have attached a binary file for the FRDM-K22F that will set itself to the VLSS2 mode and wake up via RTC alarm interrupt after a short delay.
Note that the wake-up is via a reset so the code restarts each time.
This is the sequence seen on the VCOM interface (UART at 115200 Baud):
Hello, world... FRDM-K22F
OS Heap use = 0x0479 from 0x6000
WOKEN - restoring WAIT mode
Serial number: 00
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
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
Hello - this will show you how to use a RTC alarm
to restart the processor from a low leakage mode
We'll check the RTC is running first..
1.01.1970 00:00:51
#
1.01.1970 00:00:52
#
1.01.1970 00:00:53
#Now we set an alarm to fire in 4s time..
New alarm set
1.01.1970 00:00:58
#and we command going to VLLS2 mode....
#zzzzzzzzz...(we will wake at the RTC alarm and recover via reset)
The sequence repeats over and over again - as per your requirement (although I set longer times so that it can be better monitored).
The code that I used is as follows:
extern void fnQuickTask1(TTASKTABLE *ptrTaskTable)
{
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
unsigned char ucInputMessage[HEADER_LENGTH]; // reserve space for receiving messages
static int iState = 0;
switch (iState++) {
case 0:
fnInitiateLogin(ES_SERIAL_LOGIN); // start command line interface
fnCommandInput("4\r\n", 3, SOURCE_SERIAL); // move to the admin menu
uTaskerMonoTimer(TASK_DEV_1, (DELAY_LIMIT)(1.0 * SEC), 1);
break;
case 1:
fnDebugMsg("\r\nHello - this will show you how to use a RTC alarm\r\n");
fnDebugMsg("to restart the processor from a low leakage mode\r\n");
uTaskerMonoTimer(TASK_DEV_1, (DELAY_LIMIT)(1.0 * SEC), 1);
break;
case 2:
fnDebugMsg("We'll check the RTC is running first..\r\n");
uTaskerMonoTimer(TASK_DEV_1, (DELAY_LIMIT)(0.2 * SEC), 1);
break;
case 3:
case 4:
case 5:
fnCommandInput("show_time\r\n", 11, SOURCE_SERIAL); // show the present time
uTaskerMonoTimer(TASK_DEV_1, (DELAY_LIMIT)(1.1 * SEC), 1);
break;
case 6:
fnDebugMsg("Now we set an alarm to fire in 4s time..\r\n");
fnCommandInput("set_alarm +4\r\n", 14, SOURCE_SERIAL); // set a RTC alarm to fire 4s into the future
uTaskerMonoTimer(TASK_DEV_1, (DELAY_LIMIT)(0.2 * SEC), 1);
break;
case 7:
fnDebugMsg("and we command going to VLLS2 mode....");
fnSetLowPowerMode(VLLS2_MODE);
fnDebugMsg("zzzzzzzzz...(we will wake at the RTC alarm and recover via reset)");
break;
}
while (fnRead(PortIDInternal, ucInputMessage, HEADER_LENGTH) != 0) { // read input queue to clear timer events
}
}
I did this in the uTasker project and using a single task to demonstrate the operation flow.
In addition, I first used code to configure the RTC to run from the board's 32kHz crystal
fnStartRTC(0); // start the RTC if it isn't yet operating
and I enabled a wake-up interrupt on SW2 and also on the RTC
INTERRUPT_SETUP interrupt_setup; // interrupt configuration parameters
interrupt_setup.int_type = WAKEUP_INTERRUPT; // configure as wake-up interrupt
interrupt_setup.int_handler = wakeup_interrupt;
interrupt_setup.int_priority = PRIORITY_PORT_C_INT; // interrupt priority level
interrupt_setup.int_port = PORTC; // the port that the interrupt input is on
interrupt_setup.int_port_bits = PORTC_BIT1; // the input connected (SW2 on FRDM-K22F)
interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON); // interrupt is to be falling edge sensitive
fnConfigureInterrupt((void *)&interrupt_setup); // configure wake-up on port
interrupt_setup.int_port = PORT_MODULE; // define a wake-up interrupt on a module
interrupt_setup.int_port_bits = (MODULE_RTC_ALARM); // wake-up on RTC alarm interrupt
fnConfigureInterrupt((void *)&interrupt_setup); // configure wake-up from RTC alarm
You can get the uTasker project at the links below to simply do this and many much more power-ful things without loss of development time.
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
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