Skip to content

M5Unified: Sync RTC using UTC time - #119

Open
m5agent wants to merge 1 commit into
m5stack:masterfrom
m5agent:fix/rtc-sync-utc
Open

m5agent wants to merge 1 commit into
m5stack:masterfrom
m5agent:fix/rtc-sync-utc

Conversation

@m5agent

@m5agent m5agent commented Oct 10, 2026

Copy link
Copy Markdown

Fixes #117.

M5.begin() reads the RTC as UTC through M5Unified::setSystemTimeFromRtc(), but rtc_sync() wrote localtime_r() back into the RTC. With a non-UTC timezone every boot added the UTC offset to the RTC and then to the system clock.

Use gmtime_r() so the RTC stays UTC consistently with the read path and machine.RTC().datetime().

Verification:

  • StopWatch with RX8130 and a UART-REPL build, no PoE and no StamPLC-specific code:
    • baseline: set the RTC to 11:15:00 UTC; after M5.begin() the RTC registers changed to 20:15:00 local time (UTC+9).
    • fixed: set the RTC to 04:11:15 UTC; two consecutive M5.begin() calls left both the system time and RTC registers at 04:11:15 UTC.
  • Full M5STACK_StamPLC firmware build passes against 69846518 with ESP-IDF v5.5.4.
  • The original StopWatch Wi-Fi image was restored and verified byte-for-byte at the application partition after the test.

@m5agent

m5agent commented Oct 10, 2026

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

M5.begin() writes local time into the RTC IC but the IC is read back as UTC, so the clock advances by the timezone offset on every reboot

1 participant