STM32 gotchas
62.Backup domain is not reset by setting RCC_BDCR.BDRST (unless PWR_CR.DBP is set, too)

This is one of the issues which is not documented by ST, only found by observation. While observed on an STM32F427, it probably pertains to most or all of the 'F4 family, and most likely to some or all of the other families, too.

Most STM32 families (with exceptions like the STM32L0 family) do have a separate backup power domain, which is powered through a separate VBAT pin, when the main VDD is off or low (and from VDD through an internal switch, when VDD is above the powerup threshold). This domain contains primarily the RTC, the related LSE oscillator, backup registers (which in some families are a separate block, in others they form part of the RTC), and in some families also a small portion of RAM.

To protect registers in the backup domain from inadvertent writes from the "normally-powered" domain, there is a protection bit (PWR_CR.DBP), which is cleared by normal system reset, and has to be set before any write access to the backup domain.

As the backup domain is intended to be powered all the time, registers of peripherals in the backup domain are not reset by the normal system reset, only if there was a powerdown in the backup domain, i.e. when the battery is disconnected from VBAT while VDD is powered down.

There is also an optional method to reset the backup domain, by setting the RCC_BDCR.BDRST bit. Unlike other bits in the RCC_BDCR register, this bit is not write protected by the PWR_CR.DBP bit. And, indeed, it is possible to set RCC_BDCR.BDRST while PWR_CR.DBP=0, as witnessed it being still set when reading RCC_BDCR back.

However, setting RCC_BDCR.BDRST will not reset the backup domains, as can be seen on other bits of the very same RCC_BDCR register. They get reset only after PWR_CR.DBP is set.

This behaviour is not documented in the respective STM32 user manuals.

There is an additional, potentially confusing, side effect to resetting the backup domain using RCC_BDCR.BDRST. In RTC, if BYPSHD=0 (which is the default setting), the calendar registers (RCC_TR, RCC_DR, RCC_SSR) which are in the backup domain, are not accessed by the processor directly, rather, they are periodically copied into shadow registers in the normal power/APB clock domain, and then these shadow registers are visible by the processor. When backup domain is reset using RCC_BDCR.BDRST, this copying cedes to work, but the shadow registers - not being in the backup domain - retain the last copied value. The outward behaviour is, as if the RTC would "freeze" instead of being reset. This is not anything severe or problematic, but may come as a surprise.