From 8c4d0c53f21b5e4adaf137c5c80aa1e1786bf486 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 7 Mar 2024 11:30:23 +0100 Subject: [PATCH] cpu/sam0_common: RTC: avoid negative month after POR --- cpu/sam0_common/periph/rtc_rtt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpu/sam0_common/periph/rtc_rtt.c b/cpu/sam0_common/periph/rtc_rtt.c index ff0da40b57..09266cf71b 100644 --- a/cpu/sam0_common/periph/rtc_rtt.c +++ b/cpu/sam0_common/periph/rtc_rtt.c @@ -330,6 +330,13 @@ static void _rtc_init(void) RTC->MODE2.CTRLA.reg = RTC_MODE2_CTRLA_PRESCALER_DIV1024 /* CLK_RTC_CNT = 1KHz / 1024 -> 1Hz */ | RTC_MODE2_CTRLA_CLOCKSYNC /* Clock Read Synchronization Enable */ | RTC_MODE2_CTRLA_MODE_CLOCK; + + /* RTC is all 0 after POR, avoid reading invalid date right after boot */ + if (RTC->MODE2.CLOCK.reg == 0) { + RTC->MODE2.CLOCK.reg = RTC_MODE2_CLOCK_MONTH(1) + | RTC_MODE2_CLOCK_DAY(1); + } + #ifdef RTC_MODE2_CTRLB_GP2EN /* RTC driver does not use COMP[1] or ALARM[1] */ /* Use second set of Compare registers as general purpose register */