Power efficiency is very important in embedded systems, especially in battery-powered devices like IoT devices, wearables, and remote sensors. Microcontrollers from STMicroelectronics, especially the STM32 family, have a lot of low-power modes that let developers cut down on energy use without losing any functionality.
To make systems that work well and respond quickly, you need to know how these modes work and how to switch between them reliably.
This guide goes over the design of STM32 low-power modes and shows how they are used in real-life situations by walking through a practical wake-up example.
Understanding Low-Power Modes in STM32
There are several power-saving modes for STM32 microcontrollers, and each one offers a different balance between how much energy they use, how quickly they wake up, and how long they can keep the system state. These modes are meant to slowly turn off parts of the system, which saves power while keeping as much context as needed.
The system is in run mode at the highest level, which means that the CPU and all of the peripherals are working. The device can go into sleep mode, where the CPU clock stops but the peripherals keep working, as more power-saving features are added. This lets the system wake up quickly when it gets an interrupt, and it doesn’t use too much energy.
In stop mode, most clocks stop and the system goes into a state of almost complete shutdown, keeping only the memory and register contents that are needed. This saves more power. It takes longer to wake up from stop mode than from sleep mode, but it uses a lot less power.
Standby mode is the lowest power state. In this mode, the system effectively resets itself when it wakes up. It loses most of its runtime context but uses very little power. This mode is great for programs that don’t do anything for long periods of time and only need to wake up once in a while to do something.
How Wake-Up Mechanisms Work
Entering a low-power mode is only part of the process. A reliable system must also be able to wake up when needed. STM32 devices support multiple wake-up sources, including external interrupts, timers, real-time clocks, and communication peripherals.
When the microcontroller enters a low-power state, it configures specific hardware blocks to remain active and monitor for wake-up events. For example, an external pin can be set to trigger an interrupt, or a timer can be programmed to generate a wake-up signal after a defined interval.
Upon detecting a wake-up event, the system restores clocks and resumes execution. In lighter modes such as sleep and stop, execution continues from where it left off. In standby mode, the system restarts, and the reset handler is executed again. Understanding this distinction is critical when designing firmware that must preserve or restore state after waking.
Preparing the System for Low-Power Operation
Before the system goes into low-power mode, it needs to be carefully set up so that it doesn’t use too much power. This means turning off peripherals that aren’t being used, lowering clock speeds, and making sure that only the most important parts are still working.
The way the clock is set up has a big effect on how much power it uses. Lowering the system clock frequency uses less power, and turning off high-speed oscillators can use even less power. Managing peripherals is just as important because active modules like ADCs, communication interfaces, and timers can keep using power even when the CPU is not doing anything.
The firmware also needs to set up the wake-up sources that are needed. This includes setting up interrupt lines, enabling wake-up pins, and setting up timers and real-time clocks. Correct configuration makes sure that the system can switch between low-power and active states without any problems.
Entering Low-Power Mode
Once the system is prepared, entering a low-power mode typically involves setting specific control bits and executing a low-power instruction. In STM32 devices, this is often done using instructions that signal the processor to wait for an interrupt or event.
The transition to low-power mode is immediate, and the processor halts execution until a wake-up condition is met. During this time, power consumption is significantly reduced, depending on the selected mode and system configuration.
It is important to ensure that all necessary conditions are met before entering this state. For example, pending interrupts should be cleared, and critical operations should be completed to avoid unintended behavior.
Wake-Up Example Using External Interrupt
Consider a simple example where an STM32 microcontroller enters stop mode and wakes up when a button is pressed. In this scenario, a GPIO pin is configured as an external interrupt source. The system initializes the pin, enables the interrupt, and prepares the low-power configuration.
After completing initialization, the firmware places the microcontroller into stop mode. At this point, the CPU halts, and most of the system is powered down. The GPIO interrupt remains active, monitoring for a signal change.
When the button is pressed, the external interrupt is triggered. This event wakes the microcontroller, restoring the system clocks and resuming execution. The interrupt handler is executed, allowing the firmware to respond to the event, such as toggling an LED or performing a specific task.
Because stop mode retains memory, the system continues from where it left off, making it suitable for applications that require quick recovery and minimal reinitialization.
Wake-Up Example Using Timer or RTC
Another common approach is using a timer or real-time clock to wake the system after a predefined interval. This method is useful for periodic tasks such as sensor readings or data transmission.
In this example, the firmware configures the RTC to generate a wake-up event after a specified duration. The system then enters a low-power mode, such as standby or stop. While the main system is inactive, the RTC continues running using a low-power clock source.
When the timer expires, the RTC generates a wake-up signal. In stop mode, the system resumes execution, while in standby mode, it restarts from the beginning. The firmware can then perform the required task before returning to low-power operation.
This approach is widely used in energy-efficient applications where devices must operate for extended periods on limited power sources.
Managing State After Wake-Up
Handling system state after waking from low-power mode is an important aspect of firmware design. In sleep and stop modes, most of the system state is preserved, allowing the application to continue seamlessly. However, in standby mode, the system undergoes a reset, and all initialization must be performed again.
To manage this, developers often use backup registers or non-volatile memory to store critical information before entering standby mode. Upon wake-up, the firmware can check these values and determine how to resume operation.
Proper state management ensures that the system behaves predictably and avoids data loss or inconsistent behavior.
Common Challenges and Considerations
Working with low-power modes introduces several challenges. One common issue is incomplete peripheral shutdown, which can lead to higher-than-expected power consumption. Another challenge is ensuring reliable wake-up behavior, as misconfigured interrupts or timers can prevent the system from waking correctly.
Clock reconfiguration after wake-up can also be complex, particularly in stop mode where high-speed clocks are disabled. The firmware must restore the clock system before resuming normal operation.
Testing is essential to verify that the system transitions correctly between states and that power consumption meets expectations. Measuring current draw and analyzing system behavior under different conditions helps identify and resolve potential issues.
Why Low-Power Design Matters
Efficient power management makes the battery last longer, makes less heat, and makes the whole system more reliable. Low-power operation is often a very important need in applications like remote sensors, wearable devices, and systems for monitoring industry.
STM32 microcontrollers have the tools to make this happen, but it’s up to the developer to use them correctly. Developers can make systems that balance performance and energy use by learning about low-power modes and how to wake them up properly.
Example 1: Entering Sleep Mode with Interrupt Wake-Up
In this example, the microcontroller enters sleep mode and wakes when an external interrupt occurs, such as a button press. Sleep mode is the simplest low-power state and requires minimal configuration.
The system first configures a GPIO pin as an interrupt source. Once configured, the firmware enables interrupts and executes a low-power instruction that halts the CPU while allowing peripherals to remain active.
#include "stm32f4xx.h"
void setup_button_interrupt(void) {
// Enable GPIO and SYSCFG clocks
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
// Configure PC13 as input
GPIOC->MODER &= ~(3 << (13 * 2));
// Map EXTI13 to PC13
SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PC;
// Enable EXTI line 13
EXTI->IMR |= EXTI_IMR_IM13;
EXTI->FTSR |= EXTI_FTSR_TR13;
// Enable interrupt in NVIC
NVIC_EnableIRQ(EXTI15_10_IRQn);
}
void EXTI15_10_IRQHandler(void) {
if (EXTI->PR & EXTI_PR_PR13) {
EXTI->PR |= EXTI_PR_PR13; // Clear interrupt flag
// Handle button press event
}
}
int main(void) {
setup_button_interrupt();
while (1) {
__WFI(); // Wait For Interrupt (enter sleep mode)
}
}
In this scenario, the processor halts execution and consumes less power while waiting for an interrupt. When the button is pressed, the interrupt wakes the CPU, and execution resumes immediately.
Example 2: Stop Mode with GPIO Wake-Up
Stop mode provides deeper power savings by disabling most system clocks. In this example, the system enters stop mode and wakes when a GPIO interrupt is triggered.
Before entering stop mode, the firmware configures the power control register and ensures that the wake-up source is properly set.
#include "stm32f4xx.h"
void enter_stop_mode(void) {
// Enable power control clock
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
// Clear wake-up flag
PWR->CR |= PWR_CR_CWUF;
// Set low-power mode (stop mode)
PWR->CR |= PWR_CR_LPDS;
// Enter stop mode
__WFI();
}
int main(void) {
setup_button_interrupt();
while (1) {
enter_stop_mode();
// Reconfigure system clock after wake-up
SystemInit();
// Continue execution after wake-up
}
}
In stop mode, the system consumes significantly less power than in sleep mode. When the interrupt occurs, the microcontroller restores operation, but the system clock must often be reconfigured before continuing normal execution.
Example 3: Standby Mode with RTC Wake-Up
Standby mode is the deepest low-power state and is ideal for applications that wake periodically. In this example, the real-time clock is used to wake the system after a set interval.
#include "stm32f4xx.h"
void enter_standby_mode(void) {
// Enable power control clock
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
// Clear wake-up flags
PWR->CR |= PWR_CR_CWUF;
// Enable wake-up pin or RTC
PWR->CSR |= PWR_CSR_EWUP;
// Enter standby mode
PWR->CR |= PWR_CR_PDDS;
__WFI();
}
int main(void) {
// Configure RTC wake-up timer here
while (1) {
enter_standby_mode();
// System resets after wake-up
}
}
In this case, the system effectively shuts down. When the RTC triggers a wake-up event, the microcontroller resets and begins execution from the reset handler. This behavior must be considered when designing firmware, as all initialization steps must be repeated.
The examples demonstrate how different low-power modes affect system behavior. In sleep mode, execution resumes immediately after an interrupt. In stop mode, the system retains memory but requires clock reinitialization. In standby mode, the system resets completely, requiring full reinitialization.
Choosing the correct mode depends on the application’s requirements for power consumption, wake-up time, and state retention. Understanding these trade-offs allows developers to design systems that are both efficient and responsive.

