From 0e85bb01bae6d9ec6265b45981dd87d8156dca9e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Sep 2012 18:08:40 +0000 Subject: [PATCH] Fixed bug 3567597. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_2.4.x@4677 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/RTCv1/rtc_lld.c | 21 +++++++++++++++------ readme.txt | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c index f5f83dc30..88a121cd4 100644 --- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c @@ -140,17 +140,26 @@ CH_IRQ_HANDLER(RTC_IRQHandler) { * * @notapi */ -void rtc_lld_init(void){ +void rtc_lld_init(void){ /* Required because access to PRL.*/ rtc_lld_apb1_sync(); - /* Writes preload register only if its value is not equal to desired value.*/ - if (STM32_RTCCLK != (((uint32_t)(RTC->PRLH)) << 16) + - ((uint32_t)RTC->PRLL) + 1) { + /* + * Writes preload register only if its value is not equal to desired value. + * + * Ref CD00171190: RM0008 Reference manual Cls 18.4.3 The RTC->PRL registers + * are write only. We must store the value for the pre-scaler in BKP->DR1 + * and BKP->DR1 so we know it has been set. + * The pre-scaler must not be set on every reset as RTC clock counts are + * lost when it is set. + */ + if ((STM32_RTCCLK - 1) != ((((uint32_t)BKP->DR1) << 16) | BKP->DR2)){ rtc_lld_acquire(); - RTC->PRLH = (uint16_t)((STM32_RTCCLK - 1) >> 16); - RTC->PRLL = (uint16_t)((STM32_RTCCLK - 1) & 0xFFFF); + RTC->PRLH = (uint16_t)((STM32_RTCCLK - 1) >> 16) & 0x000F; + BKP->DR1 = (uint16_t)((STM32_RTCCLK - 1) >> 16) & 0x000F; + RTC->PRLL = (uint16_t)(((STM32_RTCCLK - 1)) & 0xFFFF); + BKP->DR2 = (uint16_t)(((STM32_RTCCLK - 1)) & 0xFFFF); rtc_lld_release(); } diff --git a/readme.txt b/readme.txt index 35a41ea38..7fc02c8d0 100644 --- a/readme.txt +++ b/readme.txt @@ -79,6 +79,7 @@ ***************************************************************************** *** 2.4.3 *** +- FIX: Fixed STM32F1x rtc_lld_init glitches rtc on hard reset (bug 3567597). - FIX: Fixed STM8L, cosmic compiler: c_lreg not saved (bug 3566342). - FIX: Fixed anomaly in USB enumeration (bug 3565325). - FIX: Fixed problem with lwIP statistics (bug 3564134).