RevPi3 on Ubuntu

Rund um die Software von Revolution Pi
Post Reply
StefanoBossi
Posts: 9
Joined: 03 Jun 2020, 17:13

RevPi3 on Ubuntu

Post by StefanoBossi »

Dear forum members,
I have successfully installed the latest Ubuntu 22.04 on the Rev Pi Core, now I would like to configure the Real Time Clock.
I have loaded the rtc-pcf2127 driver

Code: Select all

root@ubuntu:~# lsmod | grep rtc
rtc_pcf2127            24576  0
but I can't see the device on the i2c bus:

Code: Select all

root@ubuntu:~# 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: -- -- -- -- -- -- -- --
And no rtc under /dev is present.

What I have to do to load properli the module?

Thanks,
Stefano Bossi
StefanoBossi
Posts: 9
Joined: 03 Jun 2020, 17:13

Re: RevPi3 on Ubuntu

Post by StefanoBossi »

I think I need to compile and install an overlay, could you point me in the direction of the right one?

Thanks,
S.
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: RevPi3 on Ubuntu

Post by dirk »

Hi this sounds like an exciting project please have a look at the following links
https://github.com/RevolutionPi
https://kunbus-gmbh.atlassian.net/servi ... 2002399028
User avatar
nicolaiB
KUNBUS
Posts: 931
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: RevPi3 on Ubuntu

Post by nicolaiB »

You can have a look at our overlay files. They are located in our kernel repository. The overlay for the Core 3(+) / Core S can be found here: https://github.com/RevolutionPi/linux/b ... verlay.dts

Nicolai
StefanoBossi
Posts: 9
Joined: 03 Jun 2020, 17:13

Re: RevPi3 on Ubuntu

Post by StefanoBossi »

Hi Dirk,
thanks for the link but I need a little more help.
Here what I tried.
* the overlay I found in https://github.com/RevolutionPi are here: https://github.com/RevolutionPi/linux/t ... s/overlays the one that seems promising is the

Code: Select all

revpi-core-overlay.dts
.
Unfortunately I can't compile the overlay because there are some includes I can't find the source.
So I have extracted the portion I am interested:

Code: Select all

/dts-v1/;
/plugin/;

/ {
    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";
                    };
            };
    };
};
I have installed the needed tools for compiling the stuff:

Code: Select all

sudo apt-get install flex bison swig device-tree-compiler
and I have compiled the extracted Device Tree

Code: Select all

dtc -o dtb -o 2129.dtbo -@ ./2129.dts
loaded the DT in the Kernel with this trick:

Code: Select all

mkdir -p /sys/kernel/config/device-tree/overlays/2129
cat 2129.dtbo > /sys/kernel/config/device-tree/overlays/2129/dtbo
Unfortunately no success :-(
The rtc is not there.

I have tried the old fashioned way of loading a module:

Code: Select all

modprobe rtc_pcf2127
echo pcf2129 0x51 /sys/class/i2c-adapter/i2c-1/new_device
Even in this try, no success :-(

Code: Select all

root@ubuntu:~# 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: -- -- -- -- -- -- -- --
I think I am pretty close but I miss something.

What do you think I am doing wrong?
Any suggestion ?

Thanks,
S.
StefanoBossi
Posts: 9
Joined: 03 Jun 2020, 17:13

Re: RevPi3 on Ubuntu

Post by StefanoBossi »

I have tried with

Code: Select all

dtoverlay=i2c-rtc,pcf2127
but no success.
The

Code: Select all

/dev/rtc
is not there and

Code: Select all

i2cdetect
is still empty :-(
Reading syslog I found an error:

Code: Select all

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?
I think I am on the right direction I just miss the last step.
StefanoBossi
Posts: 9
Joined: 03 Jun 2020, 17:13

Re: RevPi3 on Ubuntu

Post by StefanoBossi »

Finally I found a solution!!!!
No building custom modules is needed, only stock kernel configuration.
Here the trick is that the I2c used bus IS NOT THE STANDARD ONE (i.e. usually con 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

Code: Select all

/boot/firmware/config.txt
:

Code: Select all

      dtoverlay=i2c-gpio,i2c_gpio_sda=44,i2c_gpio_scl=45,bus=2
      dtoverlay=i2c-rtc,pcf2129
The first one configure the second I2c bus and assign the correct 2 GPIO, the second one 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:

Code: Select all

[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:

Code: Select all

#!/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.

Code: Select all

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,
S.
Post Reply