60. System window watchdog (WWDG)

60.1 WWDG introduction

The system window watchdog (WWDG) 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 a reset on expiry of a programmed time period, unless the program refreshes the contents of the down-counter before the T6 bit is cleared. A reset is also generated if the 7-bit down-counter value (in the control register) is refreshed before the down-counter reaches the window register value. This implies that the counter must be refreshed in a limited window.

The WWDG clock is prescaled from the APB clock and has a configurable time window that can be programmed to detect abnormally late or early application behavior.

The WWDG is best suited for applications requiring the watchdog to react within an accurate timing window.

60.2 WWDG main features

60.3 WWDG implementation

Table 578. WWDG features(1)

WWDG mode / featureWWDG
Window functionX
Early wake-up interrupt generationX
System reset generation(2)X
Capability to work in system Stop-
Capability to work in system Standby-
Capability to be frozen when the microcontroller enters in Debug mode(3)X
Option bytes to control the hardware mode(4)X

1. “X” = supported, “-” = not supported.

2. Refer to the RCC section for additional information.

3. Controlled via WWDG_STOP in DBG block.

  1. Controlled via the option byte WWDG_SW. When WWDG_SW is set in HW mode the WWDG is running as soon as the CPU is in Run or Sleep modes.

60.4 WWDG functional description

If the watchdog is activated (the WDGA bit is set in the WWDG_CR register), and when the 7-bit down-counter (T[6:0] bits) is decremented 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.

The application program must write in the WWDG_CR register at regular intervals during normal operation to prevent a reset. This operation can take place only when the counter value is lower than or equal to the window register value, and higher than 0x3F. The value to be stored in the WWDG_CR register must be between 0xFF and 0xC0.

Refer to Figure 779 for the WWDG block diagram.

60.4.1 WWDG block diagram

Figure 779. Watchdog block diagram

Block diagram of the WWDG (Window Watchdog) showing internal components and signal flow.

The diagram illustrates the internal structure of the WWDG. It includes a Register interface connected to the APB bus, containing WWDG_CFR, WWDG_SR, and WWDG_CR registers. A 7-bit down-counter (CNT) is clocked by pclk through a ÷4096 prescaler and a ÷2WDGTB prescaler. The counter output T[6:0] is compared with the window value W[6:0] from WWDG_CFR in a CMP block. The output of the CMP block (CMP = 1 when T[6:0] > W[6:0]) and the WDGA bit from WWDG_CR are combined in a logic block to generate the reset output wwdg_out_rst. Additionally, the counter output T[6:0] is checked for the value 0x40 in a block labeled '= 0x40 ?'. The output of this block, along with EWIF and EWI signals, is processed by a Logic block to generate the early interrupt output wwdg_it. A readback path exists from the counter to the WWDG_CR register.

Block diagram of the WWDG (Window Watchdog) showing internal components and signal flow.

60.4.2 WWDG internal signals

Table 579 gives the list of WWDG internal signals.

Table 579. WWDG internal input/output signals

Signal nameSignal typeDescription
pclkDigital inputAPB bus clock
wwdg_out_rstDigital outputWWDG reset signal output
wwdg_itDigital outputWWDG early interrupt output

60.4.3 Enabling the watchdog

When the user option WWDG_SW selects “Software window 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.

When the user option WWDG_SW selects “Hardware window watchdog”, the watchdog is always enabled after a reset, it cannot be disabled.

Note: Refer to Section 60.3: WWDG implementation to check the availability of the hardware window watchdog mode.

60.4.4 Controlling the down-counter

This down-counter 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 that represent 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 780). The WWDG configuration register (WWDG_CFR) contains the high limit of the window: to prevent a reset, the down-counter must be reloaded when its value is lower than or equal to the window register value, and greater than 0x3F. Figure 780 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).

60.4.5 How to program the watchdog timeout

Use the formula in Figure 780 to calculate the WWDG timeout.


Warning: When writing to the WWDG_CR register, always write 1 in the T6 bit to avoid generating an immediate reset.


Figure 780. Window watchdog timing diagram

Figure 780. Window watchdog timing diagram. The diagram shows the CNT down-counter decreasing over time, with a window defined by W[6:0] and T[6:0]. The window is divided into 'Refresh not allowed' and 'Refresh allowed' regions. The WWDG timeout (T_WWDG) is calculated as T_PCLK x 4096 x 2^WDGTB[2:0] x (T[5:0] + 1). The diagram also shows the wwdg_ewit, wwdg_rst, and T6 bit signals.

The diagram illustrates the timing of the Window Watchdog (WWDG). The CNT down-counter starts at T[6:0] and decreases linearly. The window is defined by W[6:0] and T[6:0]. The window is divided into two regions: 'Refresh not allowed' and 'Refresh allowed'. The WWDG timeout (T_WWDG) is calculated as T_PCLK x 4096 x 2^WDGTB[2:0] x (T[5:0] + 1). The diagram also shows the wwdg_ewit, wwdg_rst, and T6 bit signals. The wwdg_ewit signal is high when the counter is within the window and low otherwise. The wwdg_rst signal is high when the counter reaches 0x3F and low otherwise. The T6 bit is high when the counter is within the window and low otherwise.

Figure 780. Window watchdog timing diagram. The diagram shows the CNT down-counter decreasing over time, with a window defined by W[6:0] and T[6:0]. The window is divided into 'Refresh not allowed' and 'Refresh allowed' regions. The WWDG timeout (T_WWDG) is calculated as T_PCLK x 4096 x 2^WDGTB[2:0] x (T[5:0] + 1). The diagram also shows the wwdg_ewit, wwdg_rst, and T6 bit signals.

The formula to calculate the timeout value is given by:

\[t_{\text{WWDG}} = t_{\text{PCLK}} \times 4096 \times 2^{\text{WDGTB}[2:0]} \times (T[5:0] + 1) \quad (\text{ms})\]

where:

As an example, if APB frequency is 48 MHz, WDTB[2:0] is set to 3, and T[5:0] is set to 63:

\[t_{\text{WWDG}} = (1 / 48000) \times 4096 \times 2^3 \times (63 + 1) = 43.69\text{ms}\]

Refer to the datasheet for the minimum and maximum values of \(t_{\text{WWDG}}\).

60.4.6 Debug mode

When the device enters debug mode (processor halted), the WWDG counter either continues to work normally or stops, depending on the configuration bit in DBG module. For more details, refer to Section 40: Debug support (DBG).

60.5 WWDG interrupts

The early wake-up interrupt (EWI) can be used if specific safety operations or data logging must be performed before the reset is generated. To enable the early wake-up interrupt, the application must:

When the down-counter reaches the value 0x40, a watchdog 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 ISR must reload the WWDG counter to avoid the WWDG reset, then trigger the required actions.

The watchdog interrupt is cleared by writing 0 to the EWIF bit in the WWDG_SR register.

Note: When the watchdog interrupt cannot be served (for example due to a system lock in a higher priority task), the WWDG reset is eventually generated.

Table 580. WWDG interrupt requests

InterruptEvent flagEnable control bitInterrupt clearing methodExit from mode
VectorEventSleepStop(1)Standby(1)
WWDG(2)Early wake-up interruptEWIFEWIWrite EWIF flag to 0YesNoNo
  1. 1. The WWDG interrupt can have additional capabilities, refer to Section 60.3 for details.
  2. 2. WWDG vector corresponds to the assertion of the wwdg_it signal.

60.6 WWDG registers

Refer to Section 1.2: List of abbreviations for registers for a list of abbreviations used in register descriptions.

The peripheral registers can be accessed by halfwords (16-bit) or words (32-bit).

60.6.1 WWDG control register (WWDG_CR)

Address offset: 0x000

Reset value: 0x0000 007F

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.WDGAT[6:0]
rsrwrwrwrwrwrwrw

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, decremented every (4096 x 2^WDGTB[2:0]) PCLK cycles. A reset is produced when it is decremented from 0x40 to 0x3F (T6 becomes cleared).

60.6.2 WWDG configuration register (WWDG_CFR)

Address offset: 0x004

Reset value: 0x0000 007F

60.6.2column_2Bit 7 Bits 6:0WDGA: T[6:0]:column_5Activation bitcolumn_7column_8column_9column_10column_11column_12column_13column_14column_15RM0486
31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.WDGTB[2:0]Res.EWIRes.Res.W[6:0]
rwrwrwrsrwrwrwrwrwrwrw
Bits 13:11WDGTB[2:0]:Timer base
Bit 9EWI:Early wake-up interrupt enable
Bits 6:0W[6:0]:7-bit window value

Bits 31:14 Reserved, must be kept at reset value.

Bits 13:11 WDGTB[2:0]: Timer base The timebase of the prescaler can be modified as follows: 000: CK counter clock (PCLK div 4096) div 1 001: CK counter clock (PCLK div 4096) div 2 010: CK counter clock (PCLK div 4096) div 4 011: CK counter clock (PCLK div 4096) div 8 100: CK counter clock (PCLK div 4096) div 16 101: CK counter clock (PCLK div 4096) div 32 110: CK counter clock (PCLK div 4096) div 64 111: CK counter clock (PCLK div 4096) div 128

Bit 10 Reserved, must be kept at reset value.

Bit 9 EWI: Early wake-up interrupt enable Set by software and cleared by hardware after a reset. When set, an interrupt occurs whenever the counter reaches the value 0x40.

Bits 8:7 Reserved, must be kept at reset value.

Bits 6:0 W[6:0]: 7-bit window value These bits contain the window value to be compared with the down-counter.

ST logo
ST logo

60.6.3 WWDG status register (WWDG_SR)

Address offset: 0x008

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EWIF
rc_w0

Bits 31:1 Reserved, must be kept at reset value.

Bit 0 EWIF: Early wake-up 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. Writing 1 has no effect. This bit is also set if the interrupt is not enabled.

60.6.4 WWDG register map

The following table gives the WWDG register map and reset values.

Table 581. WWDG register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000WWDG_CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WDGAT[6:0]
Reset value01111111
0x004WWDG_CFRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WDGTB [2:0]Res.EWIRes.Res.W[6:0]
Reset value00001111111
0x008WWDG_SRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EWIF
Reset value0

Refer to Section 2.3: Memory organization for the register boundary addresses.