From 8b5833f7fed36a9dd3f1bf863ff52d8e92be2e27 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 9 Aug 2016 11:33:47 -0600 Subject: [PATCH] A consequence of Max's change to the logic to enable access to the backup domain is that every call to enabledbkp(true) must be followed by a matching call to enablebkp(false). There was one cse in both RTCC drivers where that may not always be true. --- arch/arm/src/stm32/stm32_pwr.c | 4 ++++ arch/arm/src/stm32/stm32_rtcc.c | 12 ++++++------ arch/arm/src/stm32/stm32f40xxx_rtcc.c | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) 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",