Window Watchdog (WWDG)Hardware connectionControl principleSoftware ConfigurationSoftware CodeControl FunctionExperimental phenomenon
The tutorial combines LED, buzzer, and KEY to demonstrate the hardware fault detection function of the window watchdog (WWDG).
Peripherals | Development board | Description |
---|---|---|
LED | PB3 | The anode of the LED is connected to the development board PB3, and the cathode is connected to the development board GND |
KEY1 | PA8 | One end of the KEY is connected to the PA8 pin, and the other end is connected to GND |
Buzzer (active buzzer) | PA11 |
The STM32F103RCT6 has two built-in watchdogs (independent watchdog and window watchdog), which are mainly used for system fault detection and recovery.
Watchdog | Function |
---|---|
Independent Watchdog | Used to detect whether the system is running normally |
Window Watchdog | Used to detect system failures |
Window Watchdog
The window watchdog (WWDG) is driven by the clock obtained by dividing the APB1 clock. It detects abnormal late or early operations of the application by configuring the time window.
Window Watchdog | Status |
---|---|
Feed the watchdog when the count value > window upper limit | Reset |
Feed the watchdog when the window upper limit > count value > window lower limit | Do not reset |
Count value < window lower limit | Reset |
The main function of the window watchdog is to monitor the working status of the system and prevent deadlock or infinite loop caused by software errors or unexpected events
Independent watchdog feature
Free-running down counter
Conditional reset
A reset is generated when the down counter is reloaded outside the window
A reset is generated when the down counter value is less than 0x40
If the watchdog is enabled and interrupts are enabled
When the down counter is equal to 0x40, an early wake-up interrupt (EWI) is generated to reload the counter to avoid WWDG reset
Window watchdog timeout: PCLK1=36MHz
WDGB | Minimum timeout | Maximum timeout |
---|---|---|
0 | 113us | 7.28ms |
1 | 227us | 14.56ms |
xxxxxxxxxx
The frequency division number set in the tutorial is 8, the window value is 43, and the count value is 54
Example: Counter minus 1 time (PCLK1=36MHz, frequency division number is 8)
Configure the Window Watchdog (WWDG) hardware fault detection function, no need to configure specific pins.
xxxxxxxxxx
Product supporting materials source code path: Attachment → Source Code Summary → 1.Base_Course → 13.WWDG
The tutorial only briefly introduces the code, you can open the project source code to read it.
IWDG_Start
xxxxxxxxxx
void WWDG_Start(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
WWDG_SetPrescaler(WWDG_Prescaler_8);
WWDG_SetWindowValue(43|0x40);
WWDG_Enable(54|0x40);
}
The WWDG.hex file generated by the project compilation is located in the OBJ folder of the WWDG project. Find the WWDG.hex file corresponding to the project and use the FlyMcu software to download the program into the development board.
After the program is downloaded successfully: Pressing KEY1 will trigger the dog not to be fed (equivalent to reset: LED turns off, buzzer beeps, serial port prints WWDG start!), if KEY1 is not pressed, the dog will be fed continuously (LED is always on)
xxxxxxxxxx
When using the serial port debugging assistant, you need to pay attention to the serial port settings. If the settings are wrong, the phenomenon may be inconsistent