On Tuesday, 18 August 2020 14:45:23 UTC+3, Robert Heller wrote:
>
> At Tue, 18 Aug 2020 02:40:41 -0700 (PDT) beagl...@googlegroups.com 
> <javascript:> wrote: 
> > I am using beagle Bone Black with debian image. Could any please suggest 
> > how to automatically set the system time (on every reboot) by external 
> RTC 
> > module DS3231. Once internet is connected, i want to update both system 
> > time and DS3231 with the network time. 
> > 
> > I am controlling a relay based on system time, my application should 
> take 
> > DS3231 time and run perfectly even if internet is disconnected and not 
> > available for so many days. 
> > 
> > Few things i have tried, the following content has been kept in the 
> script 
> > and running @reboot script in crontab. The system time has been changed 
> if 
> > we enter this command manually after boot but not in auto start script. 
> > Please advice. 
> > 
> > *echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device* 
> > 
> > *hwclock -r -f /dev/rtc1* 
>
> Well, the simple / dumb option would be to put the above two lines in 
> /etc/rc.local, which will restore the system clock from the RTC. 
>
> The other option is to create a proper RTC service.  A properly setup RTC 
> service will restore the system clock from the RTC early in the boot 
> process 
> and save the system clock late in the shutdown process. 
>
 
A proper RTC service is already implemented by the systemd-timesyncd 
service, installed by default on the debian images:
https://www.freedesktop.org/software/systemd/man/systemd-timesyncd.service.html

It does everything Niresh needs out of box. There's a caveat: 
systemd-timesyncd only works with */dev/rtc0* device. By default */dev/rtc0* 
is grabbed by the AM335x CPU-s internal RTC (which has no battery backup) 
and the external RTC is left with */dev/rtc1* which gets ignored. I did not 
find any way to configure systemd-timesyncd to use the other device.

Robert pointed me to a device tree which very conveniently swapped the 
device nodes for those RTCs so the external one got */dev/rtc0*. I just had 
to load the device tree via /boot/uEnv.txt and time syncing worked 
beautifully. For Niresh, I suggest trying this one:

https://github.com/beagleboard/bb.org-overlays/blob/master/src/arm/BB-I2C2-RTC-DS3231.dts

--
Kind regards,
Tarmo

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/f0fdc385-9663-4dd4-a35b-b8844bdb92f3o%40googlegroups.com.

Reply via email to