Changes

Jump to: navigation, search
no edit summary
status = "okay";
rtcds3231: ds3231@68 {
compatible = "maxim,ds3231";
reg = <0x68>;
== Accessing the rtc device ==
Setting the RTC device as <code>rtc0</code> lets the system clock be synchronized. The related section can be added to the device tree as an ''alias'': <pre class="board-terminal"> aliases { /* ds3231 is our default rtc dev (rtc0) */ rtc0 = &ds3231; rtc1 = &snvs_rtc; };</pre> The RTC device is available as <code>/dev/rtc1rtc0</code> device and the related time can be read using the <code>hwclock</code> command:
<pre class="workstation-terminal">
root@desk-mx8mp123456789:~# dmesg | grep rtc1rtc0[ 56.794607949783] rtc-ds1307 5-0068: registered as rtc1rtc0root@desk-mx8mp:~# hwclock -f /dev/rtc1rtc0
2024-03-06 16:18:28.182912+01:00
root@desk-mx8mp:~#
</pre>
 
A proper ''systemd'' service <code>/lib/systemd/system/hwrtc.service</code> can be used for synchronizing the system clock from the hardware rtc device:
 
<pre>
[Unit]
Description=Synchronise System clock to hardware RTC
DefaultDependencies=no
After=ntpdate.service
Conflicts=shutdown.target
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/hwclock -f /dev/rtc1 --hctosys
RestrictRealtime=yes
 
[Install]
WantedBy=multi-user.target
</pre>
 
and the service has to be enabled:
 
systemctl enable hwrtc.service
Now the <code>date</code> command shows the system clock synchronized at any reboot.
8,154
edits

Navigation menu