20. Window watchdog (WWDG)
Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
High-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes.
XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 768 Kbytes and 1 Mbyte.
Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
This section applies to the whole STM32F10xxx family, unless otherwise specified.
20.1 WWDG introduction
The window watchdog is used to detect the occurrence of a software fault, usually generated by external interference or by unforeseen logical conditions, which causes the application program to abandon its normal sequence. The watchdog circuit generates an MCU reset on expiry of a programmed time period, unless the program refreshes the contents of the downcounter before the T6 bit becomes cleared. An MCU reset is also generated if the 7-bit downcounter value (in the control register) is refreshed before the downcounter has reached the window register value. This implies that the counter must be refreshed in a limited window.
20.2 WWDG main features
- • Programmable free-running downcounter
- • Conditional reset
- – Reset (if watchdog activated) when the downcounter value becomes less than 0x40
- – Reset (if watchdog activated) if the downcounter is reloaded outside the window (see Figure 184 )
- • Early wakeup interrupt (EWI): triggered (if enabled and the watchdog activated) when the downcounter is equal to 0x40.
20.3 WWDG functional description
If the watchdog is activated (the WDGA bit is set in the WWDG_CR register) and when the 7-bit downcounter (T[6:0] bits) rolls over from 0x40 to 0x3F (T6 becomes cleared), it initiates a reset. If the software reloads the counter while the counter is greater than the value stored in the window register, then a reset is generated.
Figure 183. Watchdog block diagram

The application program must write in the WWDG_CR register at regular intervals during normal operation to prevent an MCU reset. This operation must occur only when the counter value is lower than the window register value. The value to be stored in the WWDG_CR register must be between 0xFF and 0xC0.
Enabling the watchdog
The watchdog is always disabled after a reset. It is enabled by setting the WDGA bit in the WWDG_CR register, then it cannot be disabled again except by a reset.
Controlling the downcounter
This downcounter is free-running, counting down even if the watchdog is disabled. When the watchdog is enabled, the T6 bit must be set to prevent generating an immediate reset.
The T[5:0] bits contain the number of increments which represents the time delay before the watchdog produces a reset. The timing varies between a minimum and a maximum value due to the unknown status of the prescaler when writing to the WWDG_CR register (see Figure 184 ). The Configuration register (WWDG_CFR) contains the high limit of the window: To prevent a reset, the downcounter must be reloaded when its value is lower than the window register value and greater than 0x3F. Figure 184 describes the window watchdog process.
Note: The T6 bit can be used to generate a software reset (the WDGA bit is set and the T6 bit is cleared).
Advanced watchdog interrupt feature
The Early Wakeup Interrupt (EWI) can be used if specific safety operations or data logging must be performed before the actual reset is generated. The EWI interrupt is enabled by setting the EWI bit in the WWDG_CFR register. When the downcounter reaches the value 0x40, an EWI interrupt is generated and the corresponding interrupt service routine (ISR) can be used to trigger specific actions (such as communications or data logging), before resetting the device.
In some applications, the EWI interrupt can be used to manage a software system check and/or system recovery/graceful degradation, without generating a WWDG reset. In this case, the corresponding interrupt service routine (ISR) should reload the WWDG counter to avoid the WWDG reset, then trigger the required actions.
The EWI interrupt is cleared by writing '0' to the EWIF bit in the WWDG_SR register.
Note: When the EWI interrupt cannot be served, e.g. due to a system lock in a higher priority task, the WWDG reset will eventually be generated.
20.4 How to program the watchdog timeout
Warning: When writing to the WWDG_CR register, always write 1 in the T6 bit to avoid generating an immediate reset.
Figure 184. Window watchdog timing diagram
![Figure 184. Window watchdog timing diagram. The diagram shows three waveforms over time. The top waveform is the T[6:0] CNT downcounter, which starts at a value of 0x3F and decreases linearly. The middle waveform is the W[6:0] window register, which is a constant value. The bottom waveform is the RESET signal, which is initially high and then goes low when the counter reaches 0x3F. The time axis is divided into two regions: 'Refresh not allowed' (from the start until the counter reaches 0x3F) and 'Refresh allowed' (from the counter reaching 0x3F until it reaches 0). The T6 bit is shown as a constant high level. The diagram is labeled ai17101c.](/RM0008-STM32F101-102-103-105-107/13be234bf2b307de3c72f2fdf45eafd8_img.jpg)
The formula to calculate the WWDG timeout value is given by:
where:
\( t_{\text{WWDG}} \) : WWDG timeout
\( t_{\text{PCLK1}} \) : APB1 clock period measured in ms
4096: value corresponding to internal divider
As an example, let us assume APB1 frequency is equal to 24 MHz, WDGTB[1:0] is set to 3 and T[5:0] is set to 63:
Refer to Table 98 for the minimum and maximum values of the \( t_{\text{WWDG}} \) .
Table 98. Minimum and maximum timeout values @36 MHz ( \( f_{\text{PCLK1}} \) )
| Prescaler | WDGTB | Min timeout value | Max timeout value |
|---|---|---|---|
| 1 | 0 | 113 µs | 7.28 ms |
| 2 | 1 | 227 µs | 14.56 ms |
| 4 | 2 | 455 µs | 29.12 ms |
| 8 | 3 | 910 µs | 58.25 ms |
20.5 Debug mode
When the microcontroller enters debug mode (Cortex®-M3 core halted), the WWDG counter either continues to work normally or stops, depending on DBG_WWDG_STOP configuration bit in DBG module. For more details, refer to Section 31.16.2: Debug support for timers, watchdog, bxCAN and I 2 C .
20.6 WWDG registers
Refer to Section 2.2 on page 45 for a list of abbreviations used in register descriptions. The peripheral registers have to be accessed by half-words (16 bits) or words (32 bits).
20.6.1 Control register (WWDG_CR)
Address offset: 0x00
Reset value: 0x0000 007F
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Reserved | |||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Reserved | WDGA | T[6:0] | |||||||||||||
| Reserved | rs | rw | |||||||||||||
Bits 31:8 Reserved, must be kept at reset value.
Bit 7 WDGA : Activation bit
This bit is set by software and only cleared by hardware after a reset. When WDGA = 1, the watchdog can generate a reset.
0: Watchdog disabled
1: Watchdog enabled
Bits 6:0 T[6:0] : 7-bit counter (MSB to LSB)
These bits contain the value of the watchdog counter. It is decremented every (4096 x 2 WDGTB[1:0] ) PCLK1 cycles. A reset is produced when it rolls over from 0x40 to 0x3F (T6 becomes cleared).
20.6.2 Configuration register (WWDG_CFR)
Address offset: 0x04
Reset value: 0x0000 007F

| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Reserved | |||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Reserved | EWI | WDGTB[1:0] | W[6:0] | ||||||||||||
| rs | rw | rw | |||||||||||||
Bit 31:10 Reserved, must be kept at reset value.
Bit 9 EWI : Early wakeup interrupt
When set, an interrupt occurs whenever the counter reaches the value 0x40. This interrupt is only cleared by hardware after a reset.
Bits 8:7 WDGTB[1:0] : Timer base
The time base of the prescaler can be modified as follows:
00: CK Counter Clock (PCLK1 div 4096) div 1
01: CK Counter Clock (PCLK1 div 4096) div 2
10: CK Counter Clock (PCLK1 div 4096) div 4
11: CK Counter Clock (PCLK1 div 4096) div 8
Bits 6:0 W[6:0] : 7-bit window value
These bits contain the window value to be compared to the downcounter.
20.6.3 Status register (WWDG_SR)
Address offset: 0x08
Reset value: 0x0000 0000

| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Reserved | |||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Reserved | EWIF | ||||||||||||||
| rc_w0 | |||||||||||||||
Bits 31:1 Reserved, must be kept at reset value.
Bit 0 EWIF : Early wakeup interrupt flag
This bit is set by hardware when the counter has reached the value 0x40. It must be cleared by software by writing '0'. A write of '1' has no effect. This bit is also set if the interrupt is not enabled.
20.6.4 WWDG register map
The following table gives the WWDG register map and reset values.
Table 99. WWDG register map and reset values
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x00 | WWDG_CR | Reserved | WDGA | T[6:0] | |||||||||||||||||||||||||||||
| Reset value | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |||||||||||||||||||||||||
| 0x04 | WWDG_CFR | Reserved | EWI | WDGTB1 | W[6:0] | ||||||||||||||||||||||||||||
| Reset value | 0 | 0 | |||||||||||||||||||||||||||||||
| 0x08 | WWDG_SR | Reserved | EWIF | ||||||||||||||||||||||||||||||
| Reset value | 0 | ||||||||||||||||||||||||||||||||
Refer to Section 3.3: Memory map for the register boundary addresses.