Electronics > Microcontrollers

Optimal code architecture for STM32 power saving?


Hello all! I'm in need of some suggestions for reducing the current consumption of an STM32F411 target. For reasons I won't get into here, I've rolled my own event processor that handles all peripheral interactions. Timer events are pushed onto an event queue by a timer ISR every 10ms. My question is, what is the optimal method of sleeping the processor in between event handles? Ideally, I'd like to implement something like this:

--- Code: ---// global object instantiations

int main(void)
    // initialize peripherals


--- End code ---

In my testing, typically only 0.3% of the CPU time is spent inside handle(), so my setup has plenty of processing bandwidth. Adding WFI() has only reduced current consumption by a few mA, nothing close to the figures listed in the datasheet. What would be the best way to accomplish this, while guaranteeing that handle() is called every 10ms?

Set a GPIO pin before WFI(); and clear it in every ISR you have. That allows you to see on oscilloscope/LA the time portion actually spent in sleep.


What does __WFI() do on a STM32F4 MCU? Are you sure you understood and read the datasheet properly?
My guess is that it just puts the MCU to sleep mode (which is the "lightest" low-power mode, and doesn't save all that much), also your additional issue here is that the MCU may wake up more often than you think (due to other interrupts), something to check. But I would first look at using one of the Stop modes, which I don't think just calling __WFI() does.

Alright, so last night I did some testing and found that it's spending less than 1ms in sleep, which I figured would be due to systick. However, if I disable systick and configure RTC for 10mS wakeup, there appears to be no change. How would I go about disabling all timer interrupts? Or is there a better way to accomplish this. I'm currently working inside the STM32Cube framework.

This may be interesting for you


[0] Message Index

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod