Skip to content

Commit

Permalink
stm32: Fix RTC based tick day change
Browse files Browse the repository at this point in the history
On starting next calendar day, result of computing time
difference between current time and previous one was negative
and should be corrected by whole day on sub seconds.
It was corrected by one hour instead resulting in
negative tick increment that caused crash at midnight.

This change fixes issue by correcting time difference computation.
  • Loading branch information
kasjer committed Oct 26, 2023
1 parent 156ea82 commit b02b2ac
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hw/mcu/stm/stm32_common/src/hal_os_tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ rtc_update_time(void)
now = rtc_time_to_sub_seconds(&alarm.AlarmTime);
delta = now - last_rtc_time;
if (delta < 0) {
delta += 3600 << SUB_SECONDS_BITS;
/* Day changed, correct delta */
delta += (24 * 3600) << SUB_SECONDS_BITS;
}
alarm.AlarmTime.SubSeconds = alarm.AlarmTime.SecondFraction - (now & alarm.AlarmTime.SecondFraction);
alarm.AlarmTime.SubSeconds -= sub_seconds_per_tick;
Expand Down

0 comments on commit b02b2ac

Please sign in to comment.