2026-04-29 3:25 AM
Hallo,
is it possible to detect in my code whether it was just loaded and started under debugger? The code should behave deifferant as usual because flash loader writes into RAM and .noinit section is modified because of this.
I have already checked RSR register. It looks the same as after software reset: CPURSTF, PINRSTF and SFTRSTF are high.
Moreover RSR gegister is independent from debug configuration: Debugger / Reset behaviour. I use ST-LINK v3 with ST-LINK GDB server.
Solved! Go to Solution.
2026-04-29 3:46 AM - edited 2026-04-29 3:46 AM
You can detect the reset reason:
And you can detect when a debugger is connected by checking the DEBUGEN bit in DHCSR (the Debug Halting Control and Status Register):
Not sure that you can directly tell whether it just uploaded code, though.
You'd probably have to implement a "sentinel" to do that ...
See also:
2026-04-29 3:46 AM - edited 2026-04-29 3:46 AM
You can detect the reset reason:
And you can detect when a debugger is connected by checking the DEBUGEN bit in DHCSR (the Debug Halting Control and Status Register):
Not sure that you can directly tell whether it just uploaded code, though.
You'd probably have to implement a "sentinel" to do that ...
See also: