Compare 0 Products     empty

This article will explain how to configure the RTC internal peripheral, needed to provide the date and clock to the application, through the device tree.

Download kernel sources

First step is to fetch kernel sources of a suitable version for your SOM. Engicam stores all the software for its devices in a git repository constantly updated, from the Kernel and U-Boot sources to the customized yocto meta-layers. For this example we will work with kernel 5.10.9 for iMX8M Plus - iCore combined with CTouch 2.0 board. The relative repository on Engicam GitHub is linux-engicam-nxp and the branch will be 5.10.9. If you are working with other SOM contact the Engicam support team to know which repository you should clone according to the Linux kernel version you are using.

  • Open your browser
  • go to https://github.com/engicam-stable/linux-engicam-nxp
  • click on the Code button and copy the https address
  • Open a shell and move into the folder you want to place the sources
  • Clone the repo with command git clone <https-addr> -b 5.10.9 (Es. git clone https://github.com/engicam-stable/linux-engicam-nxp.git -b 5.10.9)

Configure the RTC

You will find the device trees for Engicam devices in arch/arm64/boot/dts(the path will be arch/arm/boot/dts for 32bit processors) together with other device tree source files with Freescale support. The one for the hardware considered in this guide is imx8mp-icore.dts. In this combination of module and carrier the RTC peripheral is controlled by the I2C, in particular by the first I2C bus. This bus corresponds to the node i2c2 as you can see in the declaration of the aliases in the Freescale device tree source file imx8mp.dtsi:

/ {
    .
    .
    .

    aliases {
        ethernet0 = &fec;
        ethernet1 = &eqos;
        gpio0 = &gpio1;
        gpio1 = &gpio2;
        gpio2 = &gpio3;
        gpio3 = &gpio4;
        gpio4 = &gpio5;
        i2c0 = &i2c1;
        i2c1 = &i2c2;
    .
    .
    };
};

Let's assume that we need to add the NXP PCF8523 Real Time Clock to our device tree. First we need to locate the i2c2 node in the imx8mp-icore.dts device tree.Then we add the new node for the rtc peripheral, being carefull to put the correct I2C address, in this case 0x68, and the corresponding driver compatibility, nxp,pcf8523:

&i2c2 {
    clock-frequency = <100000>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_i2c2>;
    status = "okay";

    pcf8523: rtc@68 {
        compatible = "nxp,pcf8523";
        reg = <0x68>;
    };
.
.
.
};

Both the informations about the I2C address and the driver compatibility can be found in the Documentation folder following the path devicetree/bindings/rtc.

Adding driver to Linux Kernel configuration

To customize our kernel configuration you need to launch the toolchain setup environment if present, otherwise you need to perform the SDK compilation with Yocto:

. /opt/eng-imx-xwayland/5.10-gatesgarth/environment-setup-cortexa53-crypto-poky-linux
unset LDFLAGS

Then you need to setup the correct configuration file for your machine and enter the Linux Kernel configuration menu:

make imx8mp_icore_defconfig
make menuconfig

Inside this menu you can set the drivers you need and then cross-compile the new kernel image. To search for our specific driver type / and then the name of the dirver:

RTC_DRV_PCF8523

Once you found the driver and enabled it you can exit the configuration menu.

Cross-compile device tree and new image

Now for the last part we need to cross compile the new Image and the device tree using the commands:

make dtbs 
make

Once the compilation is over you need to locate the file Image and imx8mp-icore.dtb and copy them inside the Boot partition of your SD card, insert it in the module and turn on the module.

Once the system is ready you can check if the RTC peripheral works through the i2c tools and the date time tools.