STM32 gotchas
307. Debugging VBAT-domain-related peripherals and pins may get confusing, as they may need VBAT-domain unlock or reset to be changed

When debugging using the usual (re)write/compile/download/run-and-observe cycle, users are accustomed to the fact, that debuggers perform some sort of reset1 as part of the download/run procedure. Thus, every debugging cycle starts with peripheral registers being reset to their default state.

However, this is not the case of VBAT-domain peripherals. As long as the VBAT pin is powered (e.g.a battery is connected to it), they ignore the system (and also VDD-power-on) reset. Only a backup-domain reset - either by removing power from both VDD and VBAT, or via the RCC_BDCR.BKPRST bit - puts them back to their default state.

This is especially confusing, if some backup-domain register/bit/bitfield inadvertently got set to an unexpected state, e.g. due to using unitialized initialization/setup struct with some of the libraries. In such case, the unexpected effect - e.g. unwanted AM/PM mode, or PC13 or other pin being occupied by RTC - does not go away with just correcting the error and performing the debug cycle, unless the register/bit/bitfield in question is explicitly written (considering the backup-domain and RTC write protections), or the backup-domain reset is performed "manually".


1. In STM32, for the VDD-power domain, there are basically two levels of reset: system reset and power-on reset - the latter being "superset" of the former, i.e. resetting everything the former does, plus some. The differences are subtle but sometimes significant, and may cause confusion during debugging, too. Debuggers usually can't perform a power-on reset (power cycle), they perform either a software-initiated system-reset; or, if connected and configured so, a NRST-pin reset.