Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reading time after date race #115

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/STM32RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ void STM32RTC::begin(bool resetTime, Hour_Format format)
, resetTime);
_timeSet = !reinit;

syncTime();
syncDate();
syncTime();

/* fix race condition where date may have changed between reading date and time */
if (_seconds == 0 && _minutes == 0 && _hours == 0) {
syncDate();
}

syncAlarmTime();
if (!IS_RTC_DATE(_alarmDay)) {
// Use current time to init alarm members,
Expand Down Expand Up @@ -1109,6 +1115,11 @@ time_t STM32RTC::getEpoch(uint32_t *subSeconds)
syncDate();
syncTime();

/* fix race condition where date may have changed between reading date and time */
if (_seconds == 0 && _minutes == 0 && _hours == 0) {
syncDate();
}

tm.tm_isdst = -1;
/*
* mktime ignores the values supplied by the caller in the
Expand Down
Loading