Electronics > Microcontrollers

Optimal code architecture for STM32 power saving?

(1/1)

hlab:
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

    while(true)
    {
        event_processor.handle();
        __WFI();
    }
}

--- 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?

wek:
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.

JW

SiliconWizard:
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.

hlab:
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.

peter-h:
This may be interesting for you
https://www.eevblog.com/forum/microcontrollers/how-fast-does-st-32f417-enter-standby-mode/msg4056850/#msg4056850

Navigation

[0] Message Index

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