-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/stm32l0: power management updated #7329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cpu/stm32l0/include/periph_cpu.h
Outdated
|
||
/** | ||
* @brief Override the default initial PM blocker | ||
* @todo we block all modes per default, until PM is cleanly implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is missing with PM to be 'cleanly implemented' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i let the comment how it was specified for the other CPUs. But, the functions such as pm_block, pm_unblock seems to work on my side, so i don't know what is missing. (for example, at start up, i have made a pm_block(0) to prevent the CPU from going into standby mode)
But, for now, i'm still facing an issue, when my CPU is in stop mode, i have configured the RTC to trigger an alarm and wake up the CPU every 1 second, but the scheduler stop running the tasks and goes back immediatly in stop mode, moreover UART is printing wrong character at wake up.
Am i missing something or doing something wrong ? Is it possible to use RIOT with stop mode activated !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am i missing something or doing something wrong ? Is it possible to run RIOT in stop mode ?
In theory yes. Maybe @kaspar030 can give a more precise answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "stop mode" is working fine even if i need to do a clk_init in my RTC callback so that the UART continues printing characters. So this patch could be merged as "stop mode" is not activated by default.
The issue is that xtimer (based on TIM2) is stopped in stop mode, @aabadie do you thing it is possible to associate xtimer with low power timer (LPTIM1) from stm32l0 so that we still have a time base running in stop mode ?
For now, i need to use thread_sleep/thread_wakeup that is not the best way to schedule my tasks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you thing it is possible to associate xtimer with low power timer (LPTIM1) from stm32l0 so that we still have a time base running in stop mode ?
I don't know. Maybe @haukepetersen or @kaspar030 have an idea since they are working on an improved version of the xtimer that is able to work in low power modes (IIRC) ?
Thx, Here is my status : I saw that i need to do a "clk_init" after going out of stop mode. Is it right ? I'm doing it in the RTC interrupt but it should be preferable to do it in the "pm_set" function. Thank you in advance, if you have any idea about a possible issue or a missing configuration, don't hesitate to share it ;) |
@aabadie I saw that @vincent-d is working on the implementation of low power timer for stm32f4. That's exactly what i wanted to start but i was a little bit lost as i'm quite new with RIOT. Once, it will be merged, i will port his patch on stm32l0 family. |
@Marc-Aurele, first thanks for working on this topic which is very important with Low power MCU like L0. As you can noticed in #7351, other people are interested in this subject. On my side, I have a very limited knowledge on that (but I'm also interested) so I can't really help. There's obviously room here for putting a common effort on this subject in order to reach a good (enough) solution. cc'ing @kaspar030 @haukepetersen and @vincent-d who are the ones that could help the best (I think). |
Hello, I have rebased my patches. I think this patch can be merged as it is if you don't see anything wrong since low power mode are deactivated by default. Anyway, stop mode and sleep mode are working very well on stm32l0 when pm_layered feature is activated. Regards, |
Patch has been rebased on master |
Patch has been rebased on master and is ready to be merged |
There are conflicts on your PR @Marc-Aurele, can you rebase and fix them ? |
done |
Hi @aabadie What is stopping us from merging this PR ? Are we waiting for something else or do i need to rework this patch. For now, L0 family cannot go in low power without thi patch. Regards, Aurélien |
@Marc-Aurele, still having this one somewhere in my head, don't worry. I just need to find a moment to try it. |
* @brief Override the default initial PM blocker | ||
* @todo we block all modes per default, until PM is cleanly implemented | ||
*/ | ||
#define PM_BLOCKER_INITIAL { .val_u32 = 0x01010101 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just asking, do you have a reference for this hardcoded value ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is based on the periph_cpu.h file from stm32f1 family that seems to implement the low power mode feature too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is the same, I'm wondering if it's really required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this means is that there are several reasons why we MUST block PM modes. The reasons are mostly peripheral related, e.g. we don't have a flexible/dynamic way on which we can disable/enable some peripherals which SHOULD block some power modes. For instance, if we allow to go to the deepest sleep mode (peripherals off), and we make use of UART, it won't work and we have undefined behaviour, since our current peripheral implementations are unaware if we're sleeping and how deep. To solve this problem, we block by default the power modes, so the device won't go to sleep unless we say so explicitly. Until we (re)implement this conditions for all our peripherals, we need to block them by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to block them by default.
I know, but this is already the case by default ,see the link I gave
@Marc-Aurele, I (finally) gave a test to this one. I had to rebase and allowed myself to push a few changes to your branch and now it works like a charm: I could go to standby and stop mode on a b-l072z-lrwan1 board. I also tested other applications and all worked. If you are ok with the last changes, then we can merge this one. |
Hi, It's ok for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works, ACK
Looks like Murdock is down, @kaspar030 do you know what happens ? |
For now yes, this is needed to reconfigure the clocking sources for peripherals, unless peripheral's implementation is done in a way that they accept to run under low power clock sources. As far as I know, UART is the most problematic. Some CPUs feature a LPUART (Low Power UART) which is able to run in a separated clock domain, if I'm not wrong.
This is, for now, not possible using the high speed/high precision timers. xtimer gets it's base time from a given source, usually a timer running at 1MHz. In sleep mode, high speed timers are stopped, thus you also stop xtimer which has an undefined behaviour when the base timer is stopped (basically it needs a free running timer all the time). A way to avoid it is to feed xtimer with a low power, low precision timer, usually 32.768KHz present in most boards, which is not stopped when the CPU is in a low power mode, so xtimer can still work. Take a look into the kinetis implementations to have an example. |
This is done after wake up, see here. And now that #8735 is merged, this PR updates it so it is also done automatically with stm32l0 cpus |
Now, MCU is able to go in stop mode if necessary when periph_pm feature is activated. Regarding LPSDSR bit that deactivates or not regulator in stop mode, it is up to the user to set/clear this bit. In order to save power, voltage regulator can be set in low power state during stop mode but it increases wakeup time. Signed-off-by: Aurelien Fillau <aurelien.fillau@gmail.com>
Murdock is back and now green, let's merge this one. Thanks @Marc-Aurele ! |
Now, stm32l0 is able to go in sleep and stop mode. By default, low power modes are deactivated.