STM32有独立看门狗(IWDG)和窗口看门狗(WWDG)。
采用窗口看门狗(WWDG),有一个死前中断,可以用来作一个报警的功能。

独立看门狗超时时间计算公式

假设LSI是32KHz,超时时间等于 预分频系数(4)乘重装值(4095),除以LSI频率(32K)
4*4095/32000,得到512毫秒
在程序while(1)里喂狗,防止程序跑飞,HAL_IWDG_Refresh(&hiwdg1); //喂狗
配合HAL_Delay()函数测试是否配置成功。
超过512毫秒不喂狗,stm32复位重启。
窗口看门狗超时计算公式

设置PCLK1为140MHz

1400000/4096/128 = 267
(127 - 63)/267 = 239ms
(127- 127)/267 = 0ms
当窗口定时器被初始化启动后,如果在0ms---239ms之间没有进行喂狗操作,那么窗口看门狗将超时复位程序。
