FreeRTOS and STM32 Low power operation

STM32F0 Power Consumption and Potential Savings

The STM32s MSXIV drew a maximum current of 120mA at 3.3V, consuming about 396mW.

All AHB peripherals have a total consumption of 52.6μA, and all APB peripherals have a total consumption of 182μA.

The HSI oscillator and LSI oscillators have 350μA (depending on speed) and 1.2μA maximum current consumption.

Tickless Idle Mode on FreeRTOS has anecdotally lowered current consumption below 0.5mA, and STM32’s Stop Mode has lowered current consumption down to 4μA.

Power Saving Features in FreeRTOS

The Idle Task and the Idle Task Hook

The idle task in FreeRTOS is automatically created by the scheduler on startup as the lowest priority task that is always able to run.

The idle task hook is responsible for performing any application functionality at the idle priority. An alternative to using the hook is creating a task that runs at idle priority.

Tickless Idle Mode

FreeRTOS runs an idle task when there are no other active tasks running. The idle task can optionally call an Idle task hook, which can then put the MCU into a deep low power mode called the Tickless Idle Mode.

This mode stops the tick interrupts which would normally run during idle periods. Stopping the tick interrupts allows the MCU to enter a deep power saving state until either an interrupt occurs, or it is time for the RTOS kernel to transition a task into the Ready state. Typically, the tick interrupt is needed for the RTOS to keep track of time, however, the RTOS should already know how long the idle task should run for.

Example

/* ** =================================================================== ** Event : FRTOS1_vApplicationIdleHook (module Events) ** ** Component : FRTOS1 [FreeRTOS] ** Description : ** If enabled, this hook will be called when the RTOS is idle. ** This is a good place to go into low power mode. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void FRTOS1_vApplicationIdleHook(void) { /* Called whenever the RTOS is idle (from the IDLE task). Here would be a good place to put the CPU into low power mode. */ Cpu_SetOperationMode(DOM_SLEEP, NULL, NULL); /* next external interrupt will wake us up */ }

Stop Mode with the Idle Hook

From researching online, Tickless Idle Mode’s use is primarily to suppress the system tick run by FreeRTOS. Using either the idle hook or an idle priority task, the STM32 can be put into stop mode, which can also disable all clocks as well as most peripherals, bringing power draw down even further.

STM32/MCU Power Saving Features

STM32 Features

STM32 chips support three low-power modes with different compromises on power, startup time, and available wakeup sources. From the STM32F0 datasheet:

 

Sleep Mode

In Sleep mode, only the CPU is stopped. All peripherals continue to operate and can wake up the CPU when an interrupt/event occurs.

Stop Mode

Stop mode achieves very low power consumption while retaining the content of SRAM and registers. The voltage regulator can also be put either in normal or in low power mode.

Standby Mode

Standby mode achieves the lowest power consumption out of the three modes. The internal voltage regulator is switched off. After entering standby mode, SRAM and register contents are lost except for registers in the RTC domain and standby circuitry.

General MCU Power Saving

General tips for lowering power in embedded systems

  1. Turn off unused IO pins.

  2. Turn off unused peripherals.

  3. Turn off unused clocks.

  4. Throttle system clock.

Coming into MSXV, selecting a low power MCU beforehand could also have significant power savings.

Power saving programming practices

  1. Consider slowing down the scheduler interrupt.

  2. Avoid polling. Polling ensures that the CPU will stay active and use more energy.

  3. Operate on small data at one time so it stays cache.