aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2018-02-05 15:12:22 +1100
committerDamien George2018-02-05 15:12:22 +1100
commit011d1555cb12d23b68085671d903f22bac331942 (patch)
treebd6391c20983292b7de739b0a9906c452ac79b23
parent5a62f0faa62751af94a795428eddab43f7e60518 (diff)
stm32/rtc: Fix RTC init to use LSI if LSI is already selected on boot.
Upon boot the RTC early-init function should detect if LSE or LSI is already selected/running and, if so, use it. When the LSI has previously (in the previous reset cycle) been selected as the clock source the only way to reliably tell is if the RTCSEL bits of the RCC_BDCR are set to the correct LSI value. In particular the RCC_CSR bits for LSI control do not indicate if the LSI is ready even if it is selected. This patch removes the check on the RCC_CSR bits for the LSI being on and ready and only uses the check on the RCC_BDCR to see if the LSI should be used straightaway. This was tested on a PYBLITEv1.0 and with the patch the LSI persists correctly as the RTC source as long as the backup domain remains powered.
-rw-r--r--ports/stm32/rtc.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c
index 029da5fc0..de4988994 100644
--- a/ports/stm32/rtc.c
+++ b/ports/stm32/rtc.c
@@ -132,13 +132,14 @@ void rtc_init_start(bool force_init) {
// provide some status information
rtc_info |= 0x40000 | (RCC->BDCR & 7) | (RCC->CSR & 3) << 8;
return;
- } else if (((RCC->BDCR & RCC_BDCR_RTCSEL) == RCC_BDCR_RTCSEL_1) && ((RCC->CSR & 3) == 3)) {
- // LSI configured & enabled & ready --> no need to (re-)init RTC
+ } else if ((RCC->BDCR & RCC_BDCR_RTCSEL) == RCC_BDCR_RTCSEL_1) {
+ // LSI configured as the RTC clock source --> no need to (re-)init RTC
// remove Backup Domain write protection
HAL_PWR_EnableBkUpAccess();
// Clear source Reset Flag
__HAL_RCC_CLEAR_RESET_FLAGS();
- RCC->CSR |= 1;
+ // Turn the LSI on (it may need this even if the RTC is running)
+ RCC->CSR |= RCC_CSR_LSION;
// provide some status information
rtc_info |= 0x80000 | (RCC->BDCR & 7) | (RCC->CSR & 3) << 8;
return;