There are at lease these functions to integrate in RIOT Kernel.
void enter_vlpr(void); => Enter low power run mode
void exit_vlpr(void); => Go back in regular power run mode
void enter_vlps(void); => Go to low power sleep
What is the correct way to integrate this low power mode in Riot Power management?
Are there existing implementation for these low power modes for other MCUs to take in example ?
Unfortunately, it seems that low power management hasn't gotten a lot
of love for most platforms yet. The basic API is in place though, if you
wish to implement it on your platform.
This command will let you find a few areas where the API has been used:
grep -r -e 'pm_[un]*block' -e pm_set
In general I think the idea is to number the power modes such that you:
* Start by giving your lowest power mode 0
* Then find the next lowest power mode that supports features that are
a superset of the features supported by 0, and make that mode 1
* Repeat until you run out of power modes.
You then write a function pm_set in cpu/*/periph/pm.c that implements
switching the power modes. And also you set up anything that can't run
in a certain power mode to pm_block that mode, and then to pm_unblock
when it stops running. I think the kernel then handles the rest.
There may be some details I missed, because I am not super-familiar
with the system, but this should give you a good start.
Hi Olivier,
Welcome to RIOT!
There is a pull request to integrate stop modes for the Kinetis CPUs 1. There’s no VLPR or VLPW yet, but STOP, VLPS, and LLS are working. It does need a rebase though.
We could use some help reviewing this and some other related Kinetis pull requests 2, 3, 4 if you would like to help with this. Feel free to open new PRs for any other improvements you may have.
@Joakim: I cloned your repository, I checkout the pr/kinetis-pm branch and rebase from master
Then I turned ENABLE_LEDS 1 in pm.c to facilitate debugging.
I build a sample application with a very simple main() loop:
while (1){
printf("*** pause 5s ***\n");
xtimer_sleep(5);
}
With this setup, I could run the above code, but the MCU is idling in KINETIS_PM_WAIT mode
(Lowest power saving ?).
Maybe I missed something in my Makefiles or includes (llwu, pm_layered ?) to enable the advanced power saving modes ?
Are there changes to make on the board I use (pba-d-01-kw2x) too ?
Do you have a test application I can use as a reference implementation ?
My guess is that your board uses xtimer with the PIT timer hardware, try using the LPTMR instead. See the frdm-kw41z configuration for an example config (board.h, periph_conf.h). I think Mulle has a config example as well but it is disabled by default.
You might find the timer refactoring PRs helpful 1, 2, 3 (any help with testing and reviewing is welcome!)
You might also have the UART RX blocking power modes if you don’t configure the llwu pin in the UART config. Clocking mode will affect the reliability of the UART in low power mode, some clock modes take too long to recover from sleep mode so you will miss the first few characters on RX. Use FEI if unsure.
Hi Olivier,
Thanks for the offer of helping! Could you write a short review on
each of the PRs that you have used/tested to let others know what the
state is and whether anything is not working as intended?
A review from a non-maintainer can not be used to approve and merge
PRs, but it does give an indication to the people with the proper
access that a PR is ready or if it needs more work.
#7897 is still pending. If you would like to help you could run some
tests on your board with that PR and report your results. There is
still one issue reported in the PR discussion thread which I have not
looked into yet related to the phytec board and UART in low power
modes.
Can you confirm me Kinetis Low Power Modes are fully supported in Riot/master ?
Not yet, #7897 is still awaiting review and testing
Should I switch my board from PIT to LPTMR to enable these low power modes ?
Unless you have a reason for requiring better than 30.5 µs precision
on xtimer, I don't see any reason for not using LPTMR as XTIMER_DEV.
Recently added is one more PR which improves the LPTMR, in particular
it will fix a timer rollover when timer_set is called with timeout=0.
See https://github.com/RIOT-OS/RIOT/pull/10020
Can you confirm I need to declare LPTMR to get Low Power Mode working ?
You will need LPTMR if you want to be able to use low power modes when
you are using the xtimer module, which is usually required for things
like network timeouts etc.
Do you have example of working LPTMR declarations ?
I haven’t found a way to get the debugger to connect reliably with low power modes without manual intervention.
If you hold the reset button on the development board when you do a make flash until you get to the point where it has identified the CPU it should work. Release the reset and then the flashing should complete successfully. I haven’t tested on the kw2xd, but it works on at least the k22f and the kw41z.
Hope this helps.
/Joakim