Subsection 16.2.2 Configuring the IWDG
The independent watchdog has five registers (Reference Manual §20.4), four of which this course uses: the key register
IWDG_KR, the prescaler IWDG_PR, the reload register IWDG_RLR and the status register IWDG_SR. The fifth, IWDG_WINR, sets the window option we do not use. All key values are written to IWDG_KR: 0x0000 5555 unlocks the prescaler, reload and window registers; 0x0000 CCCC starts the watchdog, whose counter counts down from 0xFFF; 0x0000 AAAA reloads the counter from IWDG_RLR and prevents the reset. The prescaler IWDG_PR divides the 32 kHz LSI: 000 is divide by 4, each step doubles it, 011 is divide by 32 (a 1 ms tick), and 110 and 111 are divide by 256. The timeout is the reload value times the prescaled tick. The IWDG needs no clock enable of its own, unlike every other peripheral this term, because it is clocked by the LSI rather than from the bus that RCC gates.
Once started, the IWDG cannot be turned off by software: there is no disable bit, which is the point of a watchdog. This is not a permanent change to the chip. The IWDG only runs at all once a program has written 0x0000 CCCC to
IWDG_KR, and any reset, the watchdog’s own, the board’s reset button, or flashing a new program, starts the chip with the watchdog stopped. (Reference Manual §20.3.3 describes a hardware-watchdog option byte that starts the IWDG automatically at power-up; this course does not set it.) It keeps counting through Sleep, Stop and Standby, so a program that sleeps for longer than its watchdog timeout is reset before it wakes.
