Electrical – STM32 Reset Reason – detect debug reset

debuggingresetstm32

In my project I want to set the configuration of the RTC based on the reset source. If a reset is done via hardware reset NRST, the RTC shall be set to zero.
If there was a reset due to wake up from standby or shutdown mode, then the RTC configuration should not be erased. (I think, in that case I have a software reset of the core). This can be achieved via RCC register which stores if the reason of the reset.

How can I detect whether the controller was reset via SWD Debugger?

The debugger should not reset the RTC in my case. I found nothing about that in the reference manual. My specific model is the STM32G071, but I think that question might apply to most of the STM32.

Best Answer

You cannot distinguish a reset from the programmer.
What you can do is have the debug initialization script write a memory location you take into consideration during RTC initialization.

However, you'll probably find the PINRSTF source bit to be active almost always, except on specific soft reset conditions (eg: SFTRSTF or WWDGRSTF).

I'm not sure what you want to accomplish, but if you want to reset the RTC for debug purposes, you are better of doing this within the initialization script of your IDE.
Or if you want to reset the RTC on new program, copy the checksum of the program in backup registers (TAMP_BKPxR) and see if they match during initialization.