Ground Embedded KO Subscribe

Notes / MCU Firmware

Watchdog and low-power modes

The watchdog that resets the MCU when the program hangs, and the sleep, stop and standby modes for battery devices.

GROUND EMBEDDED · NOTEMCU Firmware 10Watchdog and low-power modesAvg 30%D1 period

Watchdog

Counter reloadMCU resetokokokhungreset
When healthy, the counter is reloaded periodically. If the program hangs and cannot reload it, the watchdog resets the MCU.

If it is not told "still alive" within a set time, it resets the MCU.

Type Characteristics
IWDG (independent) Separate LSI clock; works even if the main clock dies
WWDG (window) Resets if you are too late, and also if you are too early

Using it correctly

  • If you refresh the watchdog inside a timer interrupt, a hung main loop never causes a reset. Refresh it where you have confirmed that the main loop or all tasks are healthy.
  • With an RTOS, each task sets an "alive" flag and a supervisor task refreshes the watchdog only when it has seen all of them.
  • After a reset, use the reset-cause flags in RCC->CSR to record whether it was a watchdog reset.

Low-power modes (STM32 in general)

Runeverything onSleepCPU stoppedStopclocks off, RAM keptStandbyRAM off too
Towards the right the current falls, and the wake-up time and what is lost both grow.
Mode What stops How to wake Current
Sleep CPU only Any interrupt mA
Stop Most clocks External interrupt, RTC µA
Standby Almost everything; RAM is lost Wake-up pin, RTC Below 1 µA

After waking from Stop the clock is back on HSI, so the PLL has to be set up again. Battery life is calculated as "awake time × active current + asleep time × standby current".

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →