Skip to content

Instantly share code, notes, and snippets.

@jimboy-701
Last active September 23, 2022 14:43
Show Gist options
  • Save jimboy-701/972f153cf3e06b698d28b83a0759f8dc to your computer and use it in GitHub Desktop.
Save jimboy-701/972f153cf3e06b698d28b83a0759f8dc to your computer and use it in GitHub Desktop.
Raspberry Pi CM4 - How to enable and setup RealTimeClock

Raspberry Pi CM4 with IO Board - How to enable and setup the real time clock (RTC)

Note: This Howto \ Guide has only been tested on Raspberry Pi OS but may work with Ubuntu or other flavors of Debian Linux

When you first run the following command to check the RTC... you'll probably get the following output:

sudo hwclock -r

hwclock: Cannot access the Hardware Clock via any known method. hwclock: Use the --verbose option to see the details of our search for an access method.

First we need to disable the "fake-hwclock" which interferes with the real hwclock:

sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove sudo systemctl disable fake-hwclock

Edit /boot/config.txt and uncomment or add this line:

dtparam=i2c_vc=on

Reboot the system

reboot

The RTC will show on i2c-10 address 0x51 (7bit address), run the following command to verify this:

sudo apt install i2c-tools sudo i2cdetect -y 10

>     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
>00:                         -- -- -- -- 0c -- -- --
>10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2f
>30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
>60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>70: -- -- -- -- -- -- -- --

"To set the clock from /dev/rtc0 on a CM4 the rtc-pcf85063 module needs to be in the pi-kernel initrd... since there are issues with calling hctosys from the kernel at module load time there probably also needs to be a udev rule like:"

sudo nano /etc/udev/rules.d/60-rtc.rules
cat /etc/udev/rules.d/60-rtc.rules

ACTION=="add", SUBSYSTEM=="rtc", ATTRS{hctosys}=="0", RUN+="/usr/sbin/hwclock -s --utc"

Edit config.txt again and add the line where the below comment is located:

sudo nano /boot/config.txt
cat /boot/config.txt

...
# Additional overlays and parameters are documented /boot/overlays/README
dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi
...

Add the following to /etc/modules-load.d/modules.conf

i2c-dev rtc-pcf85063

Update initramfs:

sudo update-initramfs -c -k uname -r

List the generated initramfs and note the filename

ls -l /boot/initrd*

-rwxr-xr-x 1 root root 14003079 Dec 24 10:04 /boot/initrd.img-5.4.79-v7l+

Edit config.txt and add the new initrd-filename to the bottom of the file like so:

sudo nano /boot/config.txt
cat /boot/config.txt | tail -n 3

[all]
dtoverlay=dwc2,dr_mode=host
initramfs initrd.img-5.15.56-v8+

Reboot the system and check the RTC is fully operational

reboot
sudo hwclock -r

2022-09-23 23:37:14.345612+10:00

References

Thank you

Please feel free to leave any helpful comments or suggestions

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