Night Watch

STM32 Independent Watchdog Exercise

Task

A night watchman walks the same round of a building all night. At the end of each round he turns a key in a clock on the wall. If he ever stops, the clock rings and wakes the caretaker. A watchdog is that clock, inside the chip. It is a timer of its own that restarts the chip if the program stops checking in. Checking in is called feeding the watchdog.

Walk the rounds for as long as the board runs, and feed the watchdog once after each round: ROUND 1, ROUND 2, ROUND 3 and on, one per line Two registers set the watchdog's timeout. PR is the prescaler and RLR is the reload. Start the watchdog with PR = 3 and RLR = 999, then call walk_round(n) for round n, n counting from 1. The registers and bit fields are on the Datasheet tab.

Circuit

Block diagram: inside U1, the STM32F4, main and the given walk_round run on the core and write to IWDG, the watchdog, which counts on its own LSI clock of 32 kHz and can restart the chip; USART1 sends each ROUND line on PA9 to a terminal

Pass condition

ROUND 1, ROUND 2 and on, one line per round, in order. The watchdog is set to PR = 3 and RLR = 999 in a way the chip accepts, started, and fed once after each round.

Expected output for five rounds: the watchdog starts, then five rounds of about 10 ms each with one feed after each round, and the terminal shows ROUND 1 to ROUND 5, one per line

Notes

PR = 3 and RLR = 999 give the watchdog 1 second. Without a feed for 1 second, the watchdog restarts the chip. The watchdog counts on its own 32 kHz clock, which needs no setup.

Related challenges

Loading the interactive arena.