Skip to content

Commit f620b53

Browse files
authored
Merge pull request #72 from ABOSTM/VARIABLES_INIT
fix: initialize RTC variables even when RTC hardware is not reinitialized
2 parents 95b7514 + a2b67c1 commit f620b53

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/rtc.c

Lines changed: 4 additions & 1 deletion
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)