From a2b67c15bc342adaaac2f0bac40ae50e018b6411 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Fri, 8 Jul 2022 09:23:54 +0200 Subject: [PATCH] fix: initialize RTC variables even when RTC hardware is not reinitialized fixes #71 Signed-off-by: Alexandre Bourdiol --- src/rtc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rtc.c b/src/rtc.c index 7d7f212..dbde06f 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -364,7 +364,7 @@ bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset) BackupDate |= getBackupRegister(RTC_BKP_DATE + 1) & 0xFFFF; if ((BackupDate == 0) || reset) { /* Let HAL calculate the prescaler */ - RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND; + RtcHandle.Init.AsynchPrediv = prediv; RtcHandle.Init.OutPut = RTC_OUTPUTSOURCE_NONE; HAL_RTC_Init(&RtcHandle); // Default: saturday 1st of January 2001 @@ -395,6 +395,9 @@ bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset) // Note: year 2000 is invalid as it is the hardware reset value and doesn't raise INITS flag RTC_SetDate(1, 1, 1, 6); reinit = true; + } else { + // This initialize variables: predivAsync, redivSync and predivSync_bits + RTC_getPrediv(NULL, NULL); } #endif /* STM32F1xx */