HAL WWDG How to Use

group WWDG_How_To_Use

Main features

  • The WWDG can be started by either software or hardware (configurable through option byte).

  • Once enabled, the WWDG generates a system reset on expiry of a programmed time period, unless the program refreshes the counter (T[6;0] downcounter) before reaching 0x3F value (i.e. a reset is generated when the counter value rolls down from 0x40 to 0x3F).

  • An MCU reset is also generated if the counter value is refreshed before the counter has reached the refresh window value. This implies that the counter is refreshed within a limited window.

  • Once enabled, the WWDG cannot be disabled except by a system reset.

  • If required by the application, an Early Wakeup Interrupt can be triggered to provide warning before WWDG expiration. The Early Wakeup Interrupt (EWI) can be used if specific safety operations or data logging must be performed before the actual reset is generated. When the downcounter reaches 0x40, an interrupt occurs. This mechanism requires the WWDG interrupt line to be enabled in NVIC. Once enabled, the EWI interrupt cannot be disabled except by a system reset.

  • The WWDG counter input clock is derived from the APB clock divided by a programmable prescaler.

  • WWDG clock (Hz) = PCLK / (4096 * Prescaler)

  • WWDG timeout (ms) = 1000 * (T[5;0] + 1) / WWDG clock (Hz), where T[5;0] are the lowest 6 bits of the counter.

  • WWDG counter refresh is allowed between the following limits:

    • min time (ms) = 1000 * (Counter - Window) / WWDG clock (The minimum time represents the earliest time before refresh is allowed)

    • max time (ms) = 1000 * (Counter - 0x40) / WWDG clock (The maximum time represents the latest time before reset)

  • Typical values:

    • Counter min (T[5;0] = 0x00) at 56MHz (PCLK) with one prescaler:

      • WWDG step: approximately 73.14us (The WWDG step represents the WWDG counter period)

      • max timeout before reset: 4.681ms

    • Counter max (T[5;0] = 0x3F) at 56MHz (PCLK) with prescaler dividing by 128:

      • max timeout before reset: approximately 599.18ms

How to use

Use the WWDG HAL driver as follows:

  • Enable the WWDG interface clock if USE_HAL_WWDG_CLK_ENABLE_MODEL = HAL_CLK_ENABLE_NO. Otherwise, it is enabled in HAL_WWDG_Init().

  • Configure the allowed refresh period (minimum and maximum time values) and early interrupt status using HAL_WWDG_Start(). The WWDG is automatically enabled and its downcounter is started.

  • Refresh the WWDG counter at regular intervals during normal operation to prevent an MCU reset by calling HAL_WWDG_Refresh(). Perform this operation only when the counter is lower than the refresh window value already programmed.

Callback registration:

  • Use the compilation flag USE_HAL_WWDG_REGISTER_CALLBACKS to configure the driver callbacks dynamically.

  • Use HAL_WWDG_RegisterEarlyWakeupCallback() to register the WWDG Early Wakeup callback.

  • This function takes the HAL peripheral handle and a pointer to the callback function as parameters.

  • When calling HAL_WWDG_Init(), callbacks are reset to the corresponding legacy weak function, HAL_WWDG_EarlyWakeupCallback(), only if it has not been registered before.

  • When the compilation define USE_HAL_WWDG_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and weak callbacks are used.

Allowed Maximum time ranges:

  • Select the prescaler as follows: as long as the requested maximum time value is lower than the maximum time of a time range n, the algorithm keeps the same prescaler n. Once it exceeds the maximum time of range n, the algorithm switches to the prescaler of the range n+1.

  • The next table describes the possible maximum time ranges for each prescaler at a high frequency (144 MHz):

    Note:

  • The theoretical floating-point values presented in the following tables are rounded to the nearest integer values as only integers are used as arguments and return values for WWDG APIs.

  • For a “Not supported” value in seconds, switch to the milliseconds or microseconds unit. Similarly, for “Not supported” values in microseconds, switch to the milliseconds or seconds unit.

  • To cover all ranges, a static time unit configuration is provided and can be expressed in microseconds, milliseconds, or seconds.

    Prescaler

    Step(us)

    Max(us)

    Max(ms)

    Max(s)

    1

    28.44

    1820.44

    1.82

    Not supported

    2

    56.88

    3640.89

    3.64

    Not supported

    4

    113.77

    7281.78

    7.28

    Not supported

    8

    227.55

    14563.6

    14.56

    Not supported

    16

    455.11

    29127.1

    29.12

    Not supported

    32

    910.22

    58254.2

    58.25

    Not supported

    64

    1820.44

    116508

    116.5

    Not supported

    128

    3640.89

    233017

    233.01

    Not supported

And the possible maximum time ranges at a low frequency (17kHz), are described in next table:

Prescaler

Step(us)

Max(us)

Max(ms)

Max(s)

1

240941.17

15420235.29

15420.23

15.42

2

481882.35

30840470.59

30840.47

30.84

4

963764.7

61680941.18

61680.94

61.68

8

1927529.41

123361882.4

123361.88

123.36

16

3855058.82

246723764.7

246723.76

246.72

32

7710117.65

493447529.4

493447.52

493.44

64

15420235.3

986895058.8

986895.05

986.89

128

30840470.6

1973790118

1973790.11

1973.79