1. Window Watchdog (WWDG): Usually used to monitor software faults caused by external interference or unforeseen logic conditions when the application deviates from the normal operating sequence.
2. Window watchdog working diagram:
T[6:0] is the lower seven bits of WWDG_CR, and W[6:0] is the lower seven bits of WWDG->CFR.
It is the counter of the window watchdog, and W[6:0] is the upper window of the window watchdog. The lower window value is fixed (0X40). When the counter of the window watchdog is refreshed outside the upper window value or is lower than the lower window value, a reset will occur. The upper window value (W[6:0]) is set by the user. The window value is designed according to actual requirements, but it must be ensured that the window value is greater than 0X40, otherwise the window will not exist.
3. Related registers
a. Control register ( WWDG_CR ): Each bit is described as follows
Only the lower eight bits of WWDG_CR are valid. T[6:0] is used to store the watchdog counter value, which is updated at any time. Each window watchdog counting cycle (4096×2^WDGTB) is reduced by 1. When the counter value changes from 0X40 to 0X3F, a watchdog reset will be generated.
The WDGA bit is the activation bit of the watchdog. This bit is set to 1 by software to start the watchdog. It should be noted that once this bit is set, it can only be cleared after a hardware reset.
b. Configuration register ( WWDG_CFR ) L
EWI is an early wake-up interrupt, which reminds us some time before a reset (T[6:0]=0X40) that we need to feed the dog, otherwise it will be reset!
c. Status Register ( WWDG_SR )
This register is used to record whether there is an early wake-up flag at present. Only bit 0 of this register is valid, and the others are reserved bits. When the counter value reaches 40h, this bit is set to 1 by hardware. It must be cleared by software writing 0. Writing 1 to this bit is invalid. Even if the interrupt is not enabled, this bit will be set to 1 when the counter value reaches 0X40.
4.WWDG library function configuration steps:
1) Enable WWDG clock: WWDG is different from IWDG. IWDG has its own independent 40Khz clock, while WWDG uses the PCLK1 clock. You need to enable the clock first.
operate:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); // WWDG clock enable
2) Set the window value and frequency division number
Function to set window value: void WWDG_SetWindowValue(uint8_t WindowValue); //Entry parameter is window value
The function to set the prescaler is: void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); //The entry parameter is the prescaler value
3) Enable WWDG interrupt and group
The function to enable WWDG interrupt is: WWDG_EnableIT(); // Enable window watchdog interrupt
Interrupt priority configuration, use NVIC_Init() function.
4) Set the initial value of the counter and enable the watchdog
void WWDG_Enable(uint8_t Counter); //This function sets the initial value of the counter and enables the window watchdog.
5) Write interrupt service function
Finally, write the interrupt service function of the window watchdog, and use this function to feed the watchdog. Feeding the watchdog should be fast, otherwise when the window watchdog counter value decreases to 0X3F, it will cause a soft reset. In the interrupt service function, the EWIF bit of the status register should also be cleared.
5. Library function implementation
/*Window watchdog initialization*/
void WWDG_Init(u8 tr,u8 wr,u32 fprer)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); // WWDG clock enable
WWDG_SetPrescaler(fprer); ////Set IWDG prescaler value
WWDG_SetWindowValue(wr); //Set window value
WWDG_Enable(tr); //Enable watchdog and set counter.
WWDG_ClearFlag();
WWDG_NVIC_Init(); //Initialize window watchdog NVIC
WWDG_EnableIT(); //Enable window watchdog interrupt
}
//Reset the value of the WWDG counter
void WWDG_Set_Counter(u8 cnt)
{
WWDG_Enable(cnt);
}
//Window watchdog interrupt service routine
void WWDG_NVIC_Init()
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn; //WWDG中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //Preempt 2, sub-priority 3, group 2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //Preempt 2, sub-priority 3, group 2
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure); //NVIC initialization
}
void WWDG_IRQHandler(void)
{
// Update WWDG counter
WWDG_SetCounter(0x7F); //When this sentence is disabled, the window watchdog will reset
// Clear EWI flag */
WWDG_ClearFlag(); //Clear early wake-up interrupt flag
// Toggle GPIO_Led pin 7 */
LED1=!LED1;
}
Note: For specific function implementation, please refer to the library function file: stm32f10x_iwdg.c
reference:
《Atomic Library Function Tutorial》
Previous article:STM32 study notes TFTLCD display
Next article:STM32 study notes: independent watchdog
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- I would like to ask if the experts know the component library resources of 3554am in ad... I downloaded many component libraries but couldn't find it
- The development history of Chinese radio
- Cost-effective ADC evaluation board, EVAL-AD7606C-18
- Qorvo simplifies Wi-Fi 6E with first FEM to support 5.1 to 7.1 GHz frequency bands in a single module ...
- [RVB2601 Creative Application Development] Alibaba Cloud Testing
- Six-and-a-half-digit high-precision current source ATS-2100C
- 12 "Wanli" Raspberry Pi car - socket learning (Android sending and receiving)
- How does Windows know the last startup failure?
- An adjustable voltage regulator circuit with 6V input and 8V output
- 【2022 Digi-Key Innovation Design Competition】Latest unboxing post