How to use an RTC module with Ubuntu Core 20 on Raspberry pi 4?

Hi, i would like to know how to use an RTC (real-time-clock) module with Ubuntu Core 20 on a Raspberry Pi 4 Model B. Specifically i need to use the RTC DS3231. I would like to know how to configure and use this module on Ubuntu Core.

There are 2 ways to enable it. Either in the enabling the i2c-rtc overlay in the device tree. This will require repacking your gadget. See https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README for the overlay documentation. See https://github.com/snapcore/pi-gadget/blob/22-arm64/README.md on how to build the gadget.

Second option is to instantiate the right driver for the right address on the i2c adapter. See https://www.kernel.org/doc/Documentation/i2c/instantiating-devices in section “Method 4: Instantiate from user-space”.

Your clock should use module ds1307 and should be at address 0x68.

If you choose the second option, you will need to create a systemd service that writes into new_device. I recommend to create an udev rule to match your i2c adapter and tag it as “systemd” so you can add the right “Bindsto=” and “After=” in the service so it can start at the right time (that after the i2c adapter showed up). See https://www.freedesktop.org/software/systemd/man/systemd.device.html and https://www.freedesktop.org/software/systemd/man/udev.html

Good luck.

@abeato Please correct me if I am wrong.

@valentind thank you very much for your answers. I am trying to repacking the gadget snap, but I can’t figure out exactly which config.txt file to edit for Raspberry Pi 4 model B among the following: https://github.com/snapcore/pi-gadget/tree/22-arm64/configs. Could you please advise me which config.txt file to modify to make the snap gadget correctly?

Then I wanted to ask one more thing. Is it enough to add dtoverlay=i2c-rtc,ds1307 to the config.txt file rebuild the gadget sanp and build a bootable image of Ubuntu Core 20 that includes the snap gadget right?

You could edit config.txt-common which will always be included. Or you can add your own file like config.txt-ds1307 and add ds1307 in CORE_CFG in Makefile.

Also remember to use branch 20-arm64 if you use UC 20. I pointed to the branch for UC 22.

Correct. I do not expect anything else to be needed. But if that does not work, ask again.

It seems the 20-arm64 branch is much simpler. So forget about this. Just edit https://github.com/snapcore/pi-gadget/blob/20-arm64/configs/core/config.txt.arm64

Hi @valentind, thank you so much for the solution it works.