From 97bf000bcd7c17c1a8e6c45f21c619d61265bc12 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 7 Aug 2020 13:27:31 +0200 Subject: [PATCH] cpu/stm32: use RIOT_EPOCH --- cpu/stm32/periph/rtc_all.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cpu/stm32/periph/rtc_all.c b/cpu/stm32/periph/rtc_all.c index 8062e0e401..44285e3892 100644 --- a/cpu/stm32/periph/rtc_all.c +++ b/cpu/stm32/periph/rtc_all.c @@ -163,9 +163,8 @@ #error "rtc: unable to determine RTC SYNC and ASYNC prescalers from LSI value" #endif -/* struct tm counts years since 1900 but RTC has only two-digit year hence the - * offset of 100 years. */ -#define YEAR_OFFSET (100) +/* struct tm counts years since 1900 but RTC has only two-digit year, hence the offset */ +#define YEAR_OFFSET (RIOT_EPOCH - 1900) /* Use a magic number to determine the initial RTC source. This will be used to know if a reset of the RTC is required at initialization. */ @@ -273,7 +272,7 @@ int rtc_set_time(struct tm *time) rtc_unlock(); - RTC->DR = (val2bcd((time->tm_year % 100), RTC_DR_YU_Pos, DR_Y_MASK) | + RTC->DR = (val2bcd((time->tm_year - YEAR_OFFSET), RTC_DR_YU_Pos, DR_Y_MASK) | val2bcd(time->tm_mon + 1, RTC_DR_MU_Pos, DR_M_MASK) | val2bcd(time->tm_mday, RTC_DR_DU_Pos, DR_D_MASK)); RTC->TR = (val2bcd(time->tm_hour, RTC_TR_HU_Pos, TR_H_MASK) |