STM32H7 WWDG expires during Flash Erase
I have been stuck on a tricky little issue for some time now.
Using an STM32H753, on a reasonably large and complex application, when trying to erase the upper flash bank, the watchdog expires resetting the chip!
My suspicion is that the CPU is stalling during the erase (~5s), but watchdog keeps going until it resets.
I am running low on ideas to debug this, I am open to any help. Here are some things of significance:
- This is a long and established firmware, this issue only came about after some recent changes. Until then flash erase has worked flawlessly for years.
- Rolling back versions and changes does not help highlight the issue. It seems to be more related to flash memory placement. Even inserting one assembly instruction can cause/stop this problem.
- Watchdog has EWI interrupt enabled. This fires if I force a watchdog to occur. But it does not before the reset during flash erase.
- Flash is set up as dual bank. I am only erasing the upper bank. No memory in the upper bank is ever (intentionally) accessed by main code. With the exception of flash programming, which occurs well after erase is complete. All code only ever executes out of the lower bank.
- I checked for access to upper bank memory by setting a MPU region. A mem manage fault would occur if I forced an access to this region, but never during normal operation or during flash erase. This was tricky to do without altering flash memory placement!
- I checked errata, I am not using flash swap.
- Breakpoint on reset after watchdog, then manually tracing back running threads and interrupt stacks did not lead us to anything useful.
- I can not see what register values were right before reset as all registers and peripherals are reset by the watchdog.
- Disabling the watchdog, and showing the STM32cube tick counter (uwTick) in the SWV trace, I see it go flat during the flash erase. So the timer interrupt is not being serviced. If I pause execution during this time, the code stops during the timer ISR, but not until the flash erase finishes. I suspect the ISR code executes after the CPU is paused as some time is needed to break the CPU. But, I always see the same stack trace. But nothing in the registers or ram, or variables around that area suggests any access to the upper flash bank.
It seems most likely something is trying to access the flash while it is being erased causing the CPU to stall. I guess due to a code bug. I am after ideas, or any insight into the STM32H7 that could help track this issue to its cause.
Thanks in advance...
