Implementing STM32 low power modes — Sleep, Stop, and Standby correctly is critical for battery-powered Indian IoT applications. STM32’s sophisticated power management hardware can reduce current from 100 mA active to under 1 µA in Standby mode, extending battery life from hours to years.
Table of Contents
- STM32 Power Architecture
- Sleep Mode
- Stop Mode
- Standby Mode
- Wakeup Sources
- STM32L4: Ultra-Low Power Series
- Frequently Asked Questions
STM32 Power Architecture
STM32 microcontrollers have multiple power domains that can be independently powered down. Understanding these domains is key to achieving STM32 low power modes effectively:
- VDD domain: Main supply (GPIO, most peripherals) — powered down in Standby
- VBAT domain: RTC, backup registers — powered from backup battery during Standby
- V_CORE domain: CPU and core logic — powered down in Standby, retained in Stop
On STM32F4 series, the CPU draws ~100 mA at 168 MHz. In Standby mode with only RTC running, this drops to 2–4 µA — a 50,000× reduction.
Sleep Mode
In Sleep mode, only the CPU core clock is stopped. All peripherals (UART, SPI, DMA, ADC) continue running. Any interrupt immediately wakes the CPU — interrupt latency is 1–3 µs. Current drops from ~100 mA to ~15–30 mA on STM32F4.
/* STM32 Sleep Mode entry */
#include "stm32f4xx_hal.h"
void enterSleepMode(void) {
// Ensure pending interrupts are cleared
__WFI(); // Wait For Interrupt - enters Sleep
// CPU wakes here on any enabled interrupt
}
// Enter Sleep from HAL
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
Sleep mode is useful for: peripherals that must continue running during CPU idle periods (UART reception, ADC continuous mode), SysTick-based delays without busy-waiting.
Stop Mode
In Stop mode, all clocks are stopped (HSI, HSE, HSI14, HSI48, PLL). SRAM and register content is preserved. Wakeup sources are limited: EXTI lines (GPIO interrupts), RTC alarm/wakeup, or comparison events from comparators. Current drops to 50–300 µA on STM32F4, or as low as 2 µA on STM32L4.
/* STM32 Stop Mode with RTC wakeup */
void enterStopWithRTCWakeup(uint32_t wakeupSeconds) {
// Configure RTC wakeup timer
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, wakeupSeconds,
RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
// Disable SysTick to prevent early wakeup
HAL_SuspendTick();
// Enter Stop Mode (main regulator on = faster wake)
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
// Wake here - clocks are now at HSI (8 MHz)
// MUST restore system clock to PLL for full speed operation
SystemClock_Config(); // Re-configure PLL to full speed
HAL_ResumeTick();
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
}
Standby Mode
Standby is the deepest sleep — only VBAT domain (RTC, backup registers, WKUP pins) is powered. SRAM content is LOST on entry. On waking, MCU performs a full reset sequence (same as power-on reset). Current: 2–4 µA on STM32F4, 0.4 µA on STM32L4, 0.03 µA on STM32L4 Shutdown mode.
/* STM32 Standby Mode with WKUP pin or RTC alarm */
// IMPORTANT: Save state to backup registers or EEPROM before standby
// SRAM content will be LOST
HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, systemState); // Save state
// Configure wakeup: WKUP pin (PA0) on rising edge
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // PA0 = WKUP
// Or RTC-based wakeup
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 3600, // 1 hour
RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
// Clear all wakeup flags before entering standby
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
// Enter Standby
HAL_PWR_EnterSTANDBYMode();
// Execution continues from reset vector on wakeup, not here
// On next boot, check if waking from standby:
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
systemState = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1); // Restore state
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
}
Wakeup Sources Comparison
| Wakeup Source | Sleep | Stop | Standby |
|---|---|---|---|
| Any interrupt | Yes | No | No |
| EXTI GPIO | Yes | Yes | WKUP pins only |
| RTC alarm | Yes | Yes | Yes |
| SRAM preserved | Yes | Yes | No |
| Wake time | ~1 µs | ~50 µs | ~500 µs (full reset) |
STM32L4: Ultra-Low Power Series
For battery-optimised Indian IoT (smart meters, wearables, soil sensors), STM32L4 series is purpose-built for low power. Key advantages over STM32F4:
- Stop 2 mode: 0.4 µA with RTC running (vs 300 µA on F4)
- Shutdown mode: 30 nA (vs 4 µA Standby on F4)
- LP run mode: 10 µA at 2 MHz core clock (real CPU execution)
- Smart peripherals: LPUART, LPTIM operate independently from CPU during Stop mode
- Available in India: STM32L476RG Nucleo (₹1,500–2,000 from Mouser India)
Frequently Asked Questions
Can I enter Stop mode during FreeRTOS task execution?
Yes, via tickless idle mode. Configure FreeRTOS’s configUSE_TICKLESS_IDLE and implement vPortSuppressTicksAndSleep() for STM32 Stop mode entry when all tasks are blocked. STM32CubeIDE generates this code.
What happens to UART if I enter Stop mode?
Standard USART stops. STM32L4’s LPUART continues working in Stop 2 mode — useful for waking from serial commands while in ultra-low-power state. STM32F4 UART requires wakeup via EXTI before UART operation resumes.
Which STM32 is best for a sensor on 2xAA batteries in India?
STM32L4 series. STM32L432KC (Nucleo-L432KC, ₹800–1,200) achieves 0.4 µA in Stop 2 with RTC — a 2×AA 3000 mAh pack would last theoretically decades in sleep mode with hourly wakeups for sensor reading and transmission.
Add comment