Skip to main content
Lmoio.1
Senior
October 14, 2021
Solved

Hello, I'd like to preserve time after rebooting, when no internet connection is present. Every time I reboot I get the same date, which i presume is the late date there was an internet connection. I'd like to update this system clock with the curren

  • October 14, 2021
  • 1 reply
  • 2765 views
root@stm32mp1:~# timedatectl status
 Local time: Thu 2021-10-14 15:10:06 UTC
 Universal time: Thu 2021-10-14 15:10:06 UTC
 RTC time: Sat 2000-01-01 00:00:38
 Time zone: UTC (UTC, +0000)
System clock synchronized: no
 NTP service: active
 RTC in local TZ: no

My RTC is out of sync.

This is the date loaded after every boot. Where does system clock get it?

This is the timesyncd service.

[[0;1;32m*[[0m systemd-timesyncd.service - Network Time Synchronization
 Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
 Active: [[0;1;32mactive (running)[[0m since Thu 2021-10-14 15:09:43 UTC; 2min 23s ago
 Docs: man:systemd-timesyncd.service(8)
 Main PID: 373 (systemd-timesyn)
 Status: "Idle."
 Memory: 576.0K
 CGroup: /system.slice/systemd-timesyncd.service
 `-373 /lib/systemd/systemd-timesyncd
 
Sep 20 10:44:02 stm32mp1 systemd[1]: Starting Network Time Synchronization...
Sep 20 10:44:03 stm32mp1 systemd-timesyncd[373]: System clock time unset or jumped backwards, restoring from recorded timesta
mp: Thu 2021-10-14 15:09:43 UTC
Oct 14 15:09:43 stm32mp1 systemd[1]: Started Network Time Synchronization.

I already tried:

hwclock -w, then rebooting, then hwclock -s, but it goes back to 2000s.

Can someone help me?

This topic has been closed for replies.
Best answer by PatrickF

Ok, I got the point.

You wanted to save the current system time as the 'last ntp time' which is the one restored at boot time. right ?

I'm not SW expert, but I found that which seems working. Don't know if it is a reliable solution.

date -s "fri oct 15 09:54:00 UTC 2021" <-- if needed
touch /var/lib/systemd/timesync/clock
sync

I hope other people from community have some more clever answers.

Regards.

1 reply

PatrickF
Technical Moderator
October 14, 2021

Hi,

to 'copy' system time to RTC, you need to use the following:

hwclock --systohc --utc

See https://wiki.st.com/stm32mpu/wiki/How_to_use_the_RTC

Obviously, need a 3V battery on VBAT pin to keep time in absence of power.

Regards.

In order to give better visibility on the answered topics, please click on 'Best Answer' on the reply which solved your issue or answered your question.Tip of the day: Try Sidekick STM32 AI agent
Lmoio.1
Lmoio.1Author
Senior
October 15, 2021

The point is my cmos battery is dead, but somehow at boot, time is not the RTC reset time (Sat 2000-01-01 00:00:38), but is restored to the last time that there was an internet connection (i think it's the ntp service that does this). However this time does not keep the progress while the board is running offline. How can i update this time, so that it accounts for the time the board is on but offline at the next reboot?

Thanks

PatrickF
PatrickFBest answer
Technical Moderator
October 15, 2021

Ok, I got the point.

You wanted to save the current system time as the 'last ntp time' which is the one restored at boot time. right ?

I'm not SW expert, but I found that which seems working. Don't know if it is a reliable solution.

date -s "fri oct 15 09:54:00 UTC 2021" <-- if needed
touch /var/lib/systemd/timesync/clock
sync

I hope other people from community have some more clever answers.

Regards.

In order to give better visibility on the answered topics, please click on 'Best Answer' on the reply which solved your issue or answered your question.Tip of the day: Try Sidekick STM32 AI agent