Waking from STOP mode causes hard fault but only when debugging
I have experienced this issue on STM32L4R and STM32U5. If debugging through STOP mode (with DBGMCU_CR_DBG_STOP set), the flash memory occasionally seems to read out garbage as the MCU is coming out of STOP mode. This typically causes the CPU to hard fault.
Disconnecting the debugger and power cycling the MCU (to clear DBGMCU_CR_DBG_STOP), causes the same code to run perfectly. Alternatively, making any small code change that causes the WFI and subsequent code to change its address alignment in the flash also seems to fix the issue, even when running in the debugger. Another alternative is to increase the number of wait states, which also fixes the issue.
Is this a known issue? Has anyone else experienced it?
