diff --git a/arch/arm/src/stm32/stm32_pwr.c b/arch/arm/src/stm32/stm32_pwr.c index dfe6df0751..8fb749f767 100644 --- a/arch/arm/src/stm32/stm32_pwr.c +++ b/arch/arm/src/stm32/stm32_pwr.c @@ -83,6 +83,10 @@ static inline void stm32_pwr_modifyreg(uint8_t offset, uint16_t clearbits, uint1 * Enables access to the backup domain (RTC registers, RTC backup data registers * and backup SRAM). * + * NOTE: Reference counting is used in order to supported nested calles to this + * function. As a consequence, every call to stm32_pwr_enablebkp(true) must + * be followed by a call to stm32_pwr_enablebkp(false). + * * Input Parameters: * writable - True: enable ability to write to backup domain registers * diff --git a/arch/arm/src/stm32/stm32_rtcc.c b/arch/arm/src/stm32/stm32_rtcc.c index 21e0441c06..d27a8ddd38 100644 --- a/arch/arm/src/stm32/stm32_rtcc.c +++ b/arch/arm/src/stm32/stm32_rtcc.c @@ -729,6 +729,12 @@ int up_rtc_initialize(void) /* Remember that the RTC is initialized */ putreg32(RTC_MAGIC, RTC_MAGIC_REG); + + /* Disable write access to the backup domain (RTC registers, RTC + * backup data registers and backup SRAM). + */ + + stm32_pwr_enablebkp(false); } else { @@ -740,12 +746,6 @@ int up_rtc_initialize(void) rtc_dumpregs("Did resume"); } - /* Disable write access to the backup domain (RTC registers, RTC backup - * data registers and backup SRAM). - */ - - stm32_pwr_enablebkp(false); - if (ret != OK && nretry > 0) { rtcinfo("setup/resume ran %d times and failed with %d\n", diff --git a/arch/arm/src/stm32/stm32f40xxx_rtcc.c b/arch/arm/src/stm32/stm32f40xxx_rtcc.c index 5b1f244977..cbd136d6d5 100644 --- a/arch/arm/src/stm32/stm32f40xxx_rtcc.c +++ b/arch/arm/src/stm32/stm32f40xxx_rtcc.c @@ -1028,6 +1028,12 @@ int up_rtc_initialize(void) /* Remember that the RTC is initialized */ putreg32(RTC_MAGIC, RTC_MAGIC_REG); + + /* Disable write access to the backup domain (RTC registers, RTC + * backup data registers and backup SRAM). + */ + + stm32_pwr_enablebkp(false); } else { @@ -1039,12 +1045,6 @@ int up_rtc_initialize(void) rtc_dumpregs("Did resume"); } - /* Disable write access to the backup domain (RTC registers, RTC backup - * data registers and backup SRAM). - */ - - stm32_pwr_enablebkp(false); - if (ret != OK && nretry > 0) { rtcinfo("setup/resume ran %d times and failed with %d\n",