Author Topic: Optimal code architecture for STM32 power saving?  (Read 617 times)

0 Members and 1 Guest are viewing this topic.

Offline hlabTopic starter

  • Contributor
  • Posts: 19
  • Country: us
Optimal code architecture for STM32 power saving?
« on: May 20, 2024, 06:36:07 pm »
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: [Select]
// global object instantiations

int main(void)
{
    // initialize peripherals

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

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?
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 497
  • Country: sk
Re: Optimal code architecture for STM32 power saving?
« Reply #1 on: May 20, 2024, 06:41:51 pm »
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
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14620
  • Country: fr
Re: Optimal code architecture for STM32 power saving?
« Reply #2 on: May 20, 2024, 09:27:17 pm »
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.
 

Offline hlabTopic starter

  • Contributor
  • Posts: 19
  • Country: us
Re: Optimal code architecture for STM32 power saving?
« Reply #3 on: May 21, 2024, 02:02:37 pm »
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.
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 3743
  • Country: gb
  • Doing electronics since the 1960s...
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf