经验分享 · 2023年3月27日

STM32调试模式下禁止看门狗复位的方法

If the independent watchdog in STM32 is enabled,  the system will reset if it is hang up, even if breakpoint is triggered in debug mode,  to handle this, just add the codes below in initial routine.

__HAL_DBGMCU_FREEZE_IWDG();  //The independent watchdog counter clock is stopped when the core is halted

__HAL_DBGMCU_FREEZE_WWDG(); //pause WWDG if we use window watchdog

独立看门狗的时钟为32k分频

可以配置为32分频,这样就是1khz,方便计算

 

 

初始化后,看门狗就启动了,不需要另外手工启动

喂狗

复制代码

 

但,调试的时候,看门狗也会把程序复位,这是不行的,所以

找个地方把这两句放进去就好了

复制代码

这样,调试进入断点时不管停留多久,都不会触发看门狗

但在运行时,照样会出发看门狗

可以做一个简单的测试,初始化后,调用这两句

然后写一个延时空跑 时间超过喂狗时间

前边加断点,停留,不复位

运行这个耗时的部分, 系统复位,并且重新进入这个点