I have a hardware with an STM32F401 and I’m programming it with PlatformIO and the Arduino framework. I want to put it into low-power mode.
Unfortunately, the original example from the LowPower Library, AlarmTimedWakeup, isn’t working as expected for me. The processor never stops and always runs continuously.
If I change ONLY the mode in this example from DeepSleep to Sleep, it works as expected.
Using LowPower.sleep()
The blinking LED indicates that the RTC interrupt is working – the LED blinks at the correct rate.
On the serial output yields the following results:
When I load the program with deepSleep, I get the behavior described.
If I then reset only my target hardware, the faulty behavior persists.
If I then disconnect the ST-LINK cable, the faulty behavior remains.
If I then reset my target hardware, it works as expected.
It’s not entirely clear to me, but apparently, I don’t have to understand everything.
Okay, the power consumption isn’t where I wanted it to be, but it’s significantly closer than before.
I’ve seen this ‘gotcha’ multiple times: When the firmware is flashed via OpenOCD and a reset is done (either software or hardware), low power firmwares will behave differently. This may be due to OpenOCD e.g. enabling debug register bits for “be able to debug during standby, stop and sleep mode”
Or that the reset method done (via software or NRST toggle) is not ‘complete’ enough.
To get reliable results, I always power cycled the device completely to get the power-on-reset behavior (POR). Also make sure to disconnect the debugger completely, so that no leakage current can flow through SWDIO and SWCLK, or be parasitcally powered through the VCC / GND of the probe. Most competent dev boards will have hardware DIP switches to cut the debugger out of the line physically so that you don’t have to pull out wires constantly.