The datasheet promises about 1–2 µA in Stop 2 mode, and our board draws 300 µA. That is a typical start to work on a battery-powered device. The gap almost never comes from the microcontroller itself – it comes from pin configuration, other parts on the board, the debugger or the way current is measured. This is the order in which we hunt for the “lost” microamps.
1. Choosing a low-power mode
| Mode (e.g. STM32L4) | What keeps running | Wake-up |
|---|---|---|
| Sleep / Low-power sleep | Core stopped, peripherals and clocks running. | Any interrupt, immediately. |
| Stop 0 / 1 / 2 | High-frequency clocks off, SRAM and register contents retained; LSE/LSI, RTC, LPTIM and some peripherals (e.g. LPUART) keep running. | EXTI, RTC, selected peripherals; a few µs. |
| Standby / Shutdown | Core domain powered down, SRAM lost (except optionally SRAM2 in Standby); start-up as after reset. | WKUP pins, RTC, reset. |
For devices that wake periodically to measure and transmit, Stop 2 is usually the best trade-off: single-digit µA, and after wake-up the program continues where it stopped. Standby and Shutdown go lower, but every cycle is a full firmware restart.
2. GPIO pins – the most common source of current
ST’s AN4899 explains why a floating input pin draws current: a voltage near mid-supply makes both transistors in the input Schmitt trigger conduct. The recommendations:
- set unused pins to analog mode – it disconnects the Schmitt trigger. On STM32L4, G0 and G4 this is the reset state (except the SWD pins); on STM32F4 it is not: pins reset as inputs and must be reconfigured;
- inputs driven by external chips that go high-impedance in sleep need a pull resistor, or in Standby/Shutdown the
PWR_PUCRx/PWR_PDCRxregisters (APCbit); - check pull-ups on lines that are active during sleep: 10 kΩ to 3.3 V on a line held low is 330 µA;
- set outputs that control external chips to the state where those chips draw least – e.g. a sensor regulator’s enable line to off.
3. Other parts on the board
The microcontroller is only one consumer. Our checklist also covers: regulator quiescent current (from a fraction of a µA to tens of µA depending on the part), the battery-measurement divider (a constant current – better switched with a transistor, or very high resistances with a capacitor), power LEDs, sensors without a sleep mode, leakage of electrolytic capacitors, and transceivers with an active input stage.
4. Firmware and the debugger
- Debugger. The
DBG_STOP/DBG_STANDBYbits inDBGMCU_CR(in HAL,HAL_DBGMCU_EnableDBGStopMode()) keep the clocks running in low-power modes so the debugger stays connected – current is then orders of magnitude higher. Importantly, the debug logic stays active after the programmer is unplugged, until a power-on reset. Before measuring: firmware without these bits, ST-LINK disconnected, and a power cycle. - SysTick. In Sleep mode the SysTick interrupt wakes the core every 1 ms. Call
HAL_SuspendTick()before Sleep andHAL_ResumeTick()after wake-up. In Stop mode SysTick stops anyway. - Clock after wake-up. On exit from Stop, STM32L4 runs from MSI or HSI16 (
STOPWUCKbit) with the PLL off. If the application needs full speed, reconfigure the clocks – otherwise the UART suddenly runs at a different baud rate. - Peripheral clocks. Disable clocks of unused blocks; in Stop mode the RCC “Sleep and Stop mode enable” bits matter only for peripherals able to run in that mode.
- Wake-up. Periodic wake-up uses the RTC wake-up timer (
HAL_RTCEx_SetWakeUpTimer_IT()) clocked from LSE or LSI; external events come in through EXTI.
HAL_SuspendTick();
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
/* execution resumes here after wake-up */
SystemClock_Config(); /* restore PLL and clocks */
HAL_ResumeTick();
5. Measuring current
A multimeter on its µA range has a shunt resistance of hundreds of ohms to a few kΩ. When the device wakes and draws a few mA, the voltage drop across the meter can reset the microcontroller (the supply falls below the BOR threshold), and range switching distorts the reading. So:
- use a multimeter only for steady-state sleep current, with the range set manually;
- measure the current profile over time with a power analyser, e.g. ST’s X-NUCLEO-LPM01A with STM32CubeMonitor-Power; on Nucleo boards the IDD jumper lets you put a meter in the microcontroller supply only;
- on our own boards we add a jumper or 0 Ω resistor in the microcontroller supply rail, to measure the MCU separately from the rest of the circuit.
6. Battery life
Battery life is set by the average current:
I_avg = (I_active × t_active + I_sleep × t_sleep) / T
Worked example. A sensor wakes every 10 s, draws 3 mA for 20 ms (measurement and transmission) and 2 µA in sleep:
Iavg = (3 mA × 0.02 s + 2 µA × 9.98 s) / 10 s ≈ (60 + 20) µA·s / 10 s ≈ 8 µA.
From a CR2032 cell of about 220 mAh that is about 27,500 h in theory – just over 3 years. In practice subtract self-discharge and the capacity loss of the cell under pulsed load. The takeaway: the active phase uses 75% of the energy – cutting it from 20 to 10 ms gains more than lowering sleep current from 2 to 1 µA.
RedCan checklist: current consumption
- Low-power mode matched to the duty cycle (Stop 2 / Standby / Shutdown).
- All unused pins in analog mode, no floating inputs.
- Pull resistors checked in the sleep state, external chips switched off.
- Low-quiescent-current regulator, switchable battery divider.
- Measurement firmware without DBGMCU bits, debugger disconnected, power cycle before measuring.
- SysTick suspended in Sleep, clocks restored after Stop.
- Sleep current and current profile measured with the right instrument.
- Average current and battery life calculated including the active phase.
Related reading: HSE and LSE crystal selection and ADC measurement accuracy.
Further reading
- AN4899 – STM32 microcontroller GPIO hardware settings and low-power consumption (STMicroelectronics) – pin configuration, unused pins, current consumption.
- The family reference manual – the PWR chapter (low-power modes, entry and exit conditions) and DBGMCU.
- The datasheet – current consumption tables per mode and wake-up times.
- X-NUCLEO-LPM01A and STM32CubeMonitor-Power – ST tools for current measurement.
We write firmware for battery-powered STM32 and nRF devices together with the hardware design – see firmware and embedded software development.