Window watchdog

Demonstration in this tutorial: Combining onboard LEDs (LED1 and LED2) to demonstrate the Window Watchdog (WWDG) hardware fault detection function.

1. Software-Hardware

2. Brief principle

1. Hardware schematic diagram

image-20231030230101815

2. Physical connection diagram

image-20231030230232152

3. Control principle

Use window watchdog to detect program running status.

By controlling the high and low levels of the LED light pins, the color displayed by the LED light is controlled.

LED: high level on, low level off

LED (schematic name)Control pinFunction
LED1PG14Control LED1 on and off
LED2PG15Control LED2 on and off

STM32F103ZET6 has two built-in watchdogs (independent watchdog and window watchdog), which are mainly used for system fault detection and recovery.

WatchdogFunction
Independent WatchdogUsed to detect whether the system is running normally
Window WatchdogUsed to detect system failures

The window watchdog (WWDG) is driven by the clock obtained by dividing the APB1 clock and configures the time window to detect abnormal late or premature operations of the application.

Window WatchdogStatus
When the count value > the upper limit of the window, feed the dogReset
When the upper limit of the window > the count value > the lower limit of the window, feed the dogDo not reset
Count value < window lower limit valueReset

image-20231031122937384

image-20231031122549080

WDGBMinimum timeoutMaximum timeout
0113us7.28ms
1227us14.56ms
2455us29.12ms
3910us58.25ms
TWWDG(ms)=TPCLK140962WDGTB(T[5:0]+1)

TWWDG: WWDG timeout time

TPCLK1: APB1 time interval in ms

Example: Counter decrement time (PCLK1=36MHz, frequency division number is 8)

TWWDG(ms)=TPCLK140962WDGTB(T[5:0]+1)=136000409623(1)=0.910ms

3. Project configuration

Project configuration: Prompt configuration options during STM32CubeIDE project configuration

1. Description

Omitted project configuration part: New project, chip selection, project configuration, SYS of pin configuration, RCC configuration, clock configuration and project configuration content

The project configuration part that is not omitted is the key point that needs to be configured in this tutorial.

2. Pin configuration

You can directly select the corresponding pin number in the pin view, and the corresponding options will appear when you left-click the mouse.

image-20231030230840420

image-20231031110754655

image-20231031110832281

image-20231031110914010

Modify interrupt priority

image-20231031110948484

image-20231031111006223

image-20231030145217688

4. Main functions

It mainly introduces the functional code written by the user. For detailed code, you can open the project file provided by us yourself and enter the Bsp folder to view the source code. **

HAL library function analysis

The HAL library functions that have been introduced in the previous tutorial will not be introduced again in the tutorial!

Function: HAL_WWDG_Init

Function prototypeHAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
Function descriptionInitialize WWDG peripheral parameters
Input parametershwwdg: WWDG handle address
Return valueHAL status value: HAL_OK, HAL_ERROR, HAL_BUSY, HAL_TIMEOUT

Function: HAL_WWDG_MspInit

Function prototypevoid HAL_WWDG_MspInit(WWDG_HandleTypeDef* wwdgHandle)
Function descriptionInitialize the clock and NVIC of WWDG peripherals
Input parameterswwdgHandle: WWDG handle address
Return valueNone

Function: HAL_WWDG_IRQHandler

Function prototypevoid HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
Function descriptionWWDG interrupt handling function
Input parametershwwdg: WWDG handle address
Return valueNone

Function: HAL_WWDG_Refresh

Function prototypeHAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
Function descriptionRefresh WWDG (feed the dog)
Input parametershwwdg: WWDG handle address
Return valueHAL status value: HAL_OK, HAL_ERROR, HAL_BUSY, HAL_TIMEOUT

Function: HAL_WWDG_EarlyWakeupCallback

Function prototypevoid HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg)
Function descriptionWindow watchdog wake-up interrupt processing callback function
Input parametershwwdg: WWDG handle address
Return valueNone

5. Experimental phenomena

After downloading the program successfully, press the RESET button of the development board and observe the development board phenomenon!

Phenomenon:

Feed the dog: LED2 goes off, LED1 flashes

The dog is not fed: LED1 goes out and LED2 flashes, indicating that the hardware watchdog is abnormal.