Skip to content

Commit 16bfe3b

Browse files
committed
raspberrypi: RTC: Ensure a time is set
Until a time is set, the RTC is not running, and rtc_get_datetime() returns false without assigning to the out-parameter. In CircuitPython, this would manifest as arbitrary values being returned, since uninitialized storage on the stack was being converted into a timestamp.
1 parent be9e045 commit 16bfe3b

File tree

1 file changed

+14
-0
lines changed
  • ports/raspberrypi/common-hal/rtc

1 file changed

+14
-0
lines changed

ports/raspberrypi/common-hal/rtc/RTC.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,23 @@
2929

3030
#include "py/runtime.h"
3131
#include "src/rp2_common/hardware_rtc/include/hardware/rtc.h"
32+
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
3233

3334
void common_hal_rtc_init(void) {
35+
datetime_t t = {
36+
.year = 2020,
37+
.month = 1,
38+
.day = 1,
39+
.dotw = 3, // 0 is Sunday, so 3 is Wednesday
40+
.hour = 0,
41+
.min = 0,
42+
.sec = 0
43+
};
44+
45+
// Start the RTC
3446
rtc_init();
47+
rtc_set_datetime(&t);
48+
3549
}
3650

3751
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {

0 commit comments

Comments
 (0)