Skip to content

Commit

Permalink
cpu/sam0_common: RTC: avoid negative month after POR
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Mar 7, 2024
1 parent 6c3ab6c commit 37fdd7c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cpu/sam0_common/periph/rtc_rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 37fdd7c

Please sign in to comment.