Skip to content

Commit a2b67c1

Browse files
committed
fix: initialize RTC variables even when RTC hardware is not reinitialized
fixes stm32duino#71 Signed-off-by: Alexandre Bourdiol <[email protected]>
1 parent 95b7514 commit a2b67c1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/rtc.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
364364
BackupDate |= getBackupRegister(RTC_BKP_DATE + 1) & 0xFFFF;
365365
if ((BackupDate == 0) || reset) {
366366
/* Let HAL calculate the prescaler */
367-
RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
367+
RtcHandle.Init.AsynchPrediv = prediv;
368368
RtcHandle.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
369369
HAL_RTC_Init(&RtcHandle);
370370
// Default: saturday 1st of January 2001
@@ -395,6 +395,9 @@ bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
395395
// Note: year 2000 is invalid as it is the hardware reset value and doesn't raise INITS flag
396396
RTC_SetDate(1, 1, 1, 6);
397397
reinit = true;
398+
} else {
399+
// This initialize variables: predivAsync, redivSync and predivSync_bits
400+
RTC_getPrediv(NULL, NULL);
398401
}
399402
#endif /* STM32F1xx */
400403

0 commit comments

Comments
 (0)