Hi,
After a lot of trying, searching, reading etc. I finally managed to get the real time clock operational on my Zynthian v5.1 kit.
In hindsight it’s pretty simple, but it took me a while to find out.
The problem with the Raspberry Pi 5 it that it contains an onboard RTC. The kernel always addresses the onboard clock as /dev/rtc0
(there seems te be no way around this). The RTC on the Zynthian main board (the RV-3018, that is powered by the CR2032 battery) is addressed as /dev/rtc1
.
On startup the system time is synchronized using the onboard RTC (rtc0
). But that has no battery backup so after a power down it defaults to 1970.
There is a connector for a battery on the RPi board, but that is not accessible as it is completely covered by the large thermal block.
So, we have a clock that is used by the kernel but without a battery, and a clock that is battery powered (and operational in oram-2504.1) that is not used by the kernel.
A solution is to sync the system time/date with rtc1
on startup, but only when no network is available. That way, when the Zynthian is running stand-alone (it is a musical instrument), it still has the right date/time so if you record something the file date/time is correct.
This can be done by adding a few lines to /etc/rc.local
.
But first check if everything is correctly set up:
- Check if the main board clock is recognized and a driver is active:
(venv) root@zynthian:~# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 21 -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- UU -- -- UU -- --
50: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- --
60: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
If position 52 shows UU
everything is ok. Otherwise check /boot/firmware/config.txt
if dtoverlay=i2c-rtc,rv3028
is set.
- Check if the rtc1 clock has the right time:
(venv) root@zynthian:~# hwclock -r -f /dev/rtc1
2025-05-28 20:24:11.693684+02:00
Now add the following to /etc/rc.local
:
# Check for an IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
# Network is up, update rtc1 (on the main board) to reflect the system time.
printf "\nSetting RTC1 to system time\n"
/sbin/hwclock -wu -f /dev/rtc1
else
# No network available, use rtc1 (on the main board) to set the system time
printf "\nUsing RTC1 to set system time\n"
/sbin/hwclock -s -f /dev/rtc1
fi
After a reboot the system now always runs with the correct time.
If everything works, you can remove the fake-hwclock
but some people claim that it’s better to keep that in place.
It took some puzzling to find this solution, so I hope it saves others some time.
Kind regards,
Hans.
ps. Don’t forget the battery