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.

  • \$\begingroup\$ Well, then: how about not resetting your MCU when using SWD? \$\endgroup\$ – Marcus Müller Jun 17 at 5:04
  • \$\begingroup\$ Would be one option. But I might want to execute and step through from the beginning. \$\endgroup\$ – Timm Jun 17 at 14:02

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.