From 89b87e9c1ff312a45d37507e4a2c7cba7b4f1a88 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Fri, 19 Dec 2025 16:23:35 +0530 Subject: [PATCH] apps/examples/rtc/rtc_main.c: Fix crash of rtc app while CONFIG_RTC_HIRES is enabled - Read current RTC time instead of resetting it to (1970, 1, 1, 0, 0, 0) - Fixes assertion failure in CONFIG_RTC_HIRES mode by avoiding backward time jumps that trigger DEBUGASSERT in clock_systimespec.c --- apps/examples/rtc/rtc_main.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/examples/rtc/rtc_main.c b/apps/examples/rtc/rtc_main.c index 4a9d39663b..5268546dd8 100644 --- a/apps/examples/rtc/rtc_main.c +++ b/apps/examples/rtc/rtc_main.c @@ -103,7 +103,7 @@ static void *rtc_test(void *arg) int fd; /* populate prev_time to epoch (01-01-1970) in order reset RTC as it provides number of seconds passed starting from epoch */ - struct rtc_time prev_time = RTC_TIME_INITIALIZER(1970, 1, 1, 0, 0, 0); + struct rtc_time prev_time; struct rtc_time next_time; struct tm prev_tm; struct tm next_tm; @@ -126,11 +126,10 @@ static void *rtc_test(void *arg) printf("ERROR : Fail to open rtc.\n"); return NULL; } - - /* Initialize the RTC time as 0 */ - ret = ioctl(fd, RTC_SET_TIME, (unsigned long)&prev_time); + /* Read initial RTC time */ + ret = ioctl(fd, RTC_RD_TIME, (unsigned long)&prev_time); if (ret < 0) { - printf("ERROR : Fail to set RTC init time.\n"); + printf("ERROR : Fail to get from RTC.\n"); close(fd); return NULL; }