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.
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 */ }
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
Turn off unused IO pins.
Turn off unused peripherals.
Turn off unused clocks.
Throttle system clock.
Coming into MSXV, selecting a low power MCU beforehand could also have significant power savings.
Power saving programming practices
Consider slowing down the scheduler interrupt.
Avoid polling. Polling ensures that the CPU will stay active and use more energy.
Operate on small data at one time so it stays cache.