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.
Watchdog
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->CSRto record whether it was a watchdog reset.
Low-power modes (STM32 in general)
| 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".