Skip to content

Low Power Modes

mdemeyer edited this page Sep 21, 2020 · 1 revision

The stack supports different low power modes. This is currently a work in progress, but the basics are already implemented.

[[TOC]]

Background

Idle Hook

A downside of using a scheduler and trying to low energy consumption is knowing when there is "not much work to do". Each systick, the scheduler etablishes the next thread to be executed. If there is no thread in a ready state, the idle thread is called. The logical first step is to place the MCU in sleep mode in the IDLE thread. This is done in low power mode 1. Waking up by the systick interrupt every systick period (1 ms) is a major downside of this approach, as shown in the figure below. The energy efficiency gain of this mode is minimal, and deeper sleep modes are not feasible for such short periods.

tickless
The effects of SysTick interrupts on the power consumption (source: Mastering STM32)

Tickless Mode

The solution for this is tickless mode. With this mode, the systick interrupt is disabled for the duration of inactivity (e.g. osDelay). A second timer is used for said delay, and will suppress the systick interrupt for that duration. When the MCU wakes up from the timer or any other interrupt, the systick count is readjusted, which is essential for the scheduler.

Low Power mode 0

Low power mode 0 is the same as no low power mode, MCU and peripherals stay running at all time.

Low Power mode 1

Low power mode 1 implements two major energy saving tweaks:

  • Lower clock frequency: Sysclock is at 8 MHz instead of 56,8 MHz.
  • Custom Idle Hook: When nothing is running, the custom idle hook will run. This function enables sleep mode. Every systick (1ms) interrupt will wakeup the MCU again.

Low Power mode 2

Low power mode 2 is the more advanced low power mode. This mode also uses the lowered running Sysclock of 8 MHz, but focuses more on decreasing the inactive energy consumption. It uses tickless mode to enable deeper sleep modes for long inactive periods. With the custom tickless idle mode implementation we have, the MCU is able to enter STOP 0 mode when no thread is scheduled for a while. For now, RTC is used as a wakeup source for the stop mode. When the MCU is awake again, the systick counter is readjusted.

Furthermore, custom preStop(), postStop(), preSleep() and postSleep() functions are called before and after entering sleep or stop mode. This allow us to properly configure any peripherals, clock etc. before and aftering sleeping to further optimize the idle power consumption.


Clone this wiki locally