Dead Man's Switch

A remote sensor node uses the STM32F4 Independent Watchdog (IWDG) to automatically reset the system if the main loop ever hangs. Without it, a stuck sensor read would leave the node unresponsive until someone physically power-cycles it.

The previous developer tried to configure the IWDG but got it wrong: the configuration does not match the spec, and the timeout is off in more ways than one.

STM32F4 IWDG basics:

  • KR (key register) is key-protected: distinct key words unlock the

PR/RLR config registers for writing, start the counter, and refresh it. Consult the reference manual for the exact key words.

  • Prescaler (PR): 0=/4, 1=/8, 2=/16, 3=/32, 4=/64, 5=/128, 6-7=/256
  • Timeout ≈ (4 × 2^PR × RLR) / 32000 seconds, clocked off the 32 kHz LSI

Required behavior:

  • Prescaler chosen for /32 timing granularity
  • Reload chosen so the timeout lands at ~1 second
  • Unlock, configure, and start the watchdog before the main loop

On success the firmware prints IWDG_OK once the watchdog is armed, then one "LOOP <n>" line per main-loop iteration (n counting 1 through 3), then DONE.

Loading the interactive arena.