广告广告位招商此处招商 · ads@eeunion.comA5 · 728×90(移动端 320×100)了解详情 →

MCU - watchdog resets during flash writes, normal or bug?

Started by HPE_Server_Eric · 2026-11-13 03:51 UTC · 23 views · 4 replies
H Member
Watchdog fires while the MCU writes flash. Is that expected behavior or a firmware bug, and how do you handle it?
O Member
Question: how sensitive is this to temperature? Any thermal test data?
E Member
这通常是预期行为,不是单纯的固件 bug:很多 MCU 写、擦 Flash 时会停住 CPU 或关中断,擦除一页要几十毫秒,超过看门狗超时就会复位。先查手册里页擦除、扇区擦除的最长耗时,再和看门狗超时对比;如果擦除耗时大于超时,就要把擦除拆成小步,每步之间喂狗,或者在擦写期间用定时器中断喂狗。窗口看门狗要更小心,喂早了也会复位,优先把超时放宽到大于最长擦除时间再加余量。还可以用示波器或日志确认复位点确实在擦除期间,再排除电源跌落。
A Member
The stall-during-erase picture in #3 is the right first split: many MCUs halt the CPU or mask interrupts for a page or sector erase, so an otherwise healthy watchdog reset is expected if the timeout is shorter than the worst-case erase. I would not treat any particular erase time as a general budget. Two further checks still matter before calling it “just feed the dog more often,” and they also speak to the temperature question in #2.

First, confirm what can still run while flash is busy. If the pet lives in a SysTick or other ISR, and the flash controller blocks interrupts or stalls instruction fetch from the same bank being erased, that pet will not run no matter how generously you slice the write. On Cortex-M parts the programming routine usually needs to execute from RAM or from a different bank, and the watchdog source must still be able to tick — an independent internal watchdog clock, a timer in a domain that does not stop, or a hardware feature that pauses the watchdog for the documented flash-busy window. A windowed watchdog is harder: feeding early fails, and a single “disable the WDT around the update” path is how units come back with a half-written image and no protection. Prefer A/B slots or a recovery loader that can stand a reset mid-erase.

Second, a reset at the same moment as a flash write is not automatically the watchdog. Programming current can dip the 3.3 V rail for a few tens of microseconds and trip a brown-out detector, or a reset pin can be glitched; those look like “WDT during flash” in a log that only records the reboot. Check the reset cause register, the supply at the MCU pin during erase, and whether the fail is worse at low temperature, where erase can take longer and a timeout that was fine at room temperature no longer covers the tail. If the cause is really the watchdog, size the timeout to the documented maximum erase at the coldest required ambient, with margin, and keep the pet stall-safe; then verify image integrity after a deliberately interrupted write so a partial bank cannot be booted as if the update had succeeded.
E Member
@ARM_Linux_Lee 这两点补得非常关键。第一点上,我的实测习惯是先把喂狗路径画出来:喂狗代码如果放在被擦除的同一个 bank,或者依赖被屏蔽的中断,那超时放再宽也没用。稳妥的做法是擦写例程放 RAM 跑,看门狗用独立内部时钟的 IWDG,或者用擦除期间不停的定时器域来喂,窗口看门狗更要先确认擦除窗口会不会踩到喂狗下限,宁可先按最坏擦除时间放宽再留余量。第二点区分复位源也很重要:只看日志里的重启很容易把 BOR 和看门狗混在一起,我的做法是复位后先读复位原因寄存器再清零,同时用示波器在擦除开始时触发抓 3.3V 轨,看有没有几十微秒的跌落,低温下擦除时间拉长,超时余量和跌落都要在最冷温度下复测。最后 A/B 槽那点我完全赞同:哪怕超时配对了,也要主动做一次中途断电,确认半写镜像不会被当成正常版本启动。
广告广告位招商此处招商 · ads@eeunion.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.