Electronic – What’s causing this power spike in STM32 low power mode


I'm using an STM32L073RZ on a bare board with just the CPU and decoupling caps. I'm powering the board straight from an Otii Arc and measuring current consumption. I'm running MbedOS 5.11.2.

When I call the sleep() function the CPU goes into a low power mode, with an occasional 5mA spike in current consumption approximately every second, see the image below:

Current consumption

What is the cause of this? I'm attempting to place the CPU into STOP mode with an RTC running – this should draw, according to the datasheet, 1µA current.

Further to this, how can I tell which low power mode the sleep() function has chosen? I'm trying to stay away from the HAL because I've had many issues configuring interrupts and the like.

For completeness, here's the code that's running on the board:

#include "mbed.h"

int main() {

Best Answer

I can't speak about mbed specifically, but the general idea is that sleep() causes the execution of the current process to pause for some number of seconds, or indefinitely if no argument (equivalent to an argument of 0) is given.

In a multiprocess environment, that means that it simply yields the CPU to other processes. If there are no other processes ready to run, the OS may or may not put the CPU into a low-power state while waiting for interrupts — it depends on how the idle() task is written. This would not generally be the lowest-power state available on the CPU, however, since it wants to wake quickly when interrupts occur.

In your case, it appears to be waking up once a second to handle the system timer tick.

If you really want to get into a lower-power state, there are generally platform-specific calls for that, and that's exactly the sort of thing the HAL is for. You shouldn't avoid it, you should learn it.

After a quick search, I discovered that the documentation here: APIs - power management discusses this specifically.