3

I am using an industrial device based on a Compute Module Raspberry Pi 3 called Kunbus RevPi Core 3+.

The device is shipped with Raspbian and a pre compiled Image but I would like to install an Ubuntu Server 22.04 distro (much better for my pourpose). The Ubuntu started without a problem but I can't see the Real Time Clock.

Here is the wiring of the IC for providing the RTC and an another i2c IC.

enter image description here

The Kunbus guys mantain a Kernel patched with the Kernel Tree Overlay for the Hardware they have attacched to the board: revpi-core-overlay.dts

In the Overlay there's the specification of the RTC IC:

fragment@3 {
        target = <&i2c1>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&i2c1_pins>;
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            rtc@51 {
                compatible = "nxp,pcf2129";
                reg = <0x51>;
                status = "okay";
            };

            crypto@60 {
                compatible = "atmel,atecc508a";
                reg = <0x60>;
                status = "okay";
            };
        };
    };

So, if I have understood here the IC nxp,pcf2129 is on the line 1 with an address 0x51

First try, load the module manually

With the info I found the the Overlay and in the datasheet I tried to load the kernel module manually.

I found the driver in the kernel tree rtc-pcf2127 and I have loaded the module:

sudo modprobe rtc-pcf2127

The modules was loaded:

ubuntu@ubuntu:~$ lsmod | grep rtc
rtc_pcf2127            24576  0

According to the documentation I found here: instantiating-devices I have tried to assign the driver an address:

echo pcf2129 0x51 /sys/class/i2c-adapter/i2c-1/new_device

But no /dev/rtc has appeared:

ubuntu@ubuntu:~$ sudo ls -al /dev/rtc
ls: cannot access '/dev/rtc': No such file or directory

scanning the i2c bus has no answere too:

ubuntu@ubuntu:~$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

How could properly use the rtc device?

Thanks,

S.

7
  • You should try compiling the dts file to a dtb (using dtc, the device tree compiler), then you can include it via /boot/config.txt.
    – goldilocks
    Mar 8, 2023 at 13:23
  • I have tried but it doesn't compile because at the start of the file there are 2 include: #include <dt-bindings/gpio/gpio.h> #include <dt-bindings/pinctrl/bcm2835.h> and I don't know where to find them. Mar 8, 2023 at 16:15
  • github.com/RevolutionPi/linux/tree/…
    – goldilocks
    Mar 8, 2023 at 17:33
  • Yes, that's the GitHub of the kernel they use but I have the Ubuntu kernel, I would like just to let the RTC to Work, not all the other fancy hardware stuff. Mar 8, 2023 at 18:01
  • Ahhhh no, I got the point... you mean that the two includes stay there! mmmmm, I'll try Mar 8, 2023 at 18:04

2 Answers 2

0

Fiddling with modprobe is ancient history (as are customised kernels).

All modern Linux use Device Tree to configure hardware.
There a i2c-rtc overlay which adds support for a number of I2C Real Time Clock devices.

All you need to do is include dtoverlay=i2c-rtc,pcf2129 in config.txt.

See https://raspberrypi.stackexchange.com/a/72974/8697 and https://raspberrypi.stackexchange.com/a/100127/8697

1
  • I have tried with dtoverlay=i2c-rtc,pcf2129 and with dtoverlay=i2c-rtc,pcf2127 but no success. The /dev/rtc is not there and i2cdetect is still empty :-( Reading syslog I found an error: Mar 8 08:48:16 ubuntu kernel: [ 2.807099] rtc-pcf2127-i2c: probe of 1-0051 failed with error -121 What does it mean? Wrong address? Mar 8, 2023 at 9:35
0

Finally I found a solution!!!!

No building custom modules is needed, only stock kernel configuration. The trick is that the I2c used bus IS NOT THE STANDARD ONE (i.e. usually with Raspberry the I2c bus is on GPIO 2 and GPIO 3, which on Kunbus are used for other pourpose). The GPIO where the RTC is attached are the GPIO 44 and GPIO 45, you could check on the provided schematic and you could even see that there are the two pull up resistors needed by the bus to properly work.

That was the difficult thing to spot, as soon as I have understood that I have decided to configure a second I2c bus and let the RTC driver use that.

  1. Configure the Tree Overlay

I have added these two lines to

/boot/firmware/config.txt

Code:

dtoverlay=i2c-gpio,i2c_gpio_sda=44,i2c_gpio_scl=45,bus=2
dtoverlay=i2c-rtc,pcf2129

The first line configure the second I2c bus and assign the correct 2 GPIO, the second line ask to the kernel to use the driver for the pcf2129 for RTC.

  • Create a Service for Systemd

In the service you have to create a new device when the system start up:

[Unit]
Description=RTC configuration for pcf2129

[Service]
ExecStart=/usr/local/bin/configrtc.sh

[Install]
WantedBy=multi-user.target

This is the script used in the service:

#!/bin/bash
echo pca2129 0x51 > /sys/class/i2c-dev/i2c-2/device/new_device
sleep 0.5
hwclock -s || hwclock -w

In this way I have the RTC device working at startup every time with my Ubuntu Server 22.04.

root@kunbus02:~# i2cdetect -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Hope that this little tutorial could be of some help to some other users.

Regards,

Stefano

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.