I am working on an STM32L432. I am trying to implement low-power features. Specifically, I am using the Tickless-Idle mode to put the MCU to sleep when it enters the Idle task. I am using a periodic interrupt to wake it up periodically, and do a minimal processing (about 100 us worth of MCU cycles).
I would like to have the following behaviour:
- The MCU wakes up at periodic intervals (once every 125 ms).
- It does its 100us processing.
- It falls back to sleep immediately upon entering the Idle task (if there is no other task ready of course)
The behaviour that I see instead when configEXPECTEDIDLETIMEBEFORESLEEP is set to the default (and minimum) value of 2, is that after waking up, the MCU stays awake for a minimum of 1 tick period (1ms in my case: too long).
I tried to set configEXPECTEDIDLETIMEBEFORESLEEP to 1, and then I have the behaviour that I need. But setting configEXPECTEDIDLETIMEBEFORESLEEP to 1 creates a compile error that says: "#error configEXPECTEDIDLETIMEBEFORESLEEP must not be less than 2".
I can easily disable that error message, but before I do that, I would like to understand better what the risks are.
Note that in that project, a tight accounting of ticks is not requried. The tick counter can freeze once in a while, or skip a beat, without any noticeable effect.
I guess the reason will be something to do with rounding the value down in the algorithm because you enter sleep part of the way through a tick period, and you dont want an underflow. Guessing though. Try setting it to 1 and see what happens. You say clock accuracy is not a problem for you so if you get underflows just edit the code to guard that from happening.
When I set it to 1, it does what I need: i.e. falls to sleep the very next time the MCU enters the Idle task... usually a few 100us after waking up.
I am worried about unforeseen side-effects though, and so I would like to understand what the rationale was for keeping configEXPECTEDIDLETIMEBEFORESLEEP > 2
The following line, and one other...
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + (
ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
...requires the expected idle time to be 1 or higher.
In addition, in a normal application it is not desirable to enter low
power mode for too short a sleep, as that can increase power consumption
rather than reduce it. That is because you need to do additional
execution to calculate the time going into the sleep and then going out
again, plus you have to power down then get inrush when powering up the
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.