BBai-64: Create a device tree overlay for GPS PPS support

Hello,
I am trying to use an Adafruit GPS Module with a BeagleBone AI64 (BBAI64) to synchronize the system time. For the GPS Module to work an uart connection and one additional GPIO is required.

I need help by creating a device tree overlay to use a gpio as a PPS source. I have tried to create an example for BBAI64 from a working BeagleBone Black (BBB) Device Tree Overlay. I dont need help with the userspace software configuration for gpsd or chrony.

I have the uart running by adding the uart overlay for it in /boot/firmware/extlinux/extlinux.conf

Content of /boot/firmware/extlinux/extlinux.conf:

label Linux eMMC
    kernel /Image
    append root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait net.ifnames=0 quiet
    fdtdir /
    fdtoverlays /overlays/BONE-UART1.dtbo #/overlays/BBAI64-P9_18-GPS-PPS.dtbo
    initrd /initrd.img

I have tried to create another overlay for the PPS support but when I am adding it, I am always unable to boot.
To be frank, I am quite new to the Device Tree and Overlays in General.

Using the Connector Tables I have tried to alter the following working example for an BBB into an example for the BBAI64.

EXPAND working example for BBB

/*
*
* Virtual cape for UART1 on connector pins P9.24 P9.26 w/PPS on P9.12
* 
* Based on this thread:
*   https://forum.beagleboard.org/t/beaglebone-black-gps-pps-and-chrony-for-time-sync/897/17
*/

/dts-v1/;
/plugin/;

#include <dt-bindings/board/am335x-bbw-bbb-base.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/am33xx.h>

/{
    compatible = "ti,beaglebone-black";

    part-nmumber = "BB-UART-GPS";
    version = "00A0";

    exclusive-use = "P9.12", "P9.24", "P9.26", "uart1";

    fragment@0 {
        target=<&ocp>;
        __overlay__ {
            P9_12_pinmux{status="disabled";};
            P9_24_pinmux{status="disabled";};
            P9_26_pinmux{status="disabled";};
        };
    };

    fragment@1 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            bb_uart1_pins: pinmux_bb_uart1_pins {
                pinctrl-single,pins = <
                    BONE_P9_24 (PIN_OUTPUT | MUX_MODE0)	/* uart1_txd.uart1_txd */
                    BONE_P9_26 (PIN_INPUT | MUX_MODE0)	/* uart1_rxd.uart1_rxd */
                >;
            };

            bb_gps_pps_pins: pinmux_bb_gps_pps_pins {
                pinctrl-single,pins = <
                    BONE_P9_12 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio1_28 */
                >;
            };
        };
    };

    fragment@2 {
        target = <&uart1>;
        __overlay__ {
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&bb_uart1_pins>;
        };
    };

    fragment@3 {
        target-path = "/";
        __overlay__ {
            gps_pps {
                status = "okay";
                compatible = "pps-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <&bb_gps_pps_pins>;
                gpios = <&gpio1 28 0>;
            }; 
        };
    };
};

The example includes lines for uart and pps. Since UART1 is already usable with the provided overlays, I have tried to remove everything but configuration for PPS:

REMARK: I cant boot when adding this overlay to extlinux.conf. So please dont add the following overlay in the current state unless you know how to remove it again.

I am trying to get the PPS working on P9_18. Any other free gpio would be suitable aswell for me.

EXPAND faulty example for BBAI64

/*
* Based on this thread:
*   https://forum.beagleboard.org/t/beaglebone-black-gps-pps-and-chrony-for-time-sync/897/17
*/

/dts-v1/;
/plugin/;

#include <dt-bindings/board/k3-j721e-bone-pins.h>   /*<- #include <dt-bindings/board/am335x-bbw-bbb-base.h>*/
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/k3.h>                 /*<- #include <dt-bindings/pinctrl/am33xx.h> */

/{
    compatible = "beagle,j721e-beagleboneai64", "ti,j721e";
    model = "BeagleBoard.org BeagleBone AI-64";

    part-nmumber = "BB-UART-GPS";
    version = "00A0";

    exclusive-use = "P9.18";

    fragment@0 {
        target=<&ocp>;
        __overlay__ {
            P9_18_pinmux{status="disabled";};
        };
    };

    fragment@1 {
        target = <&main_pmx0>;
        __overlay__ {
            bb_gps_pps_pins: pinmux_bb_gps_pps_pins {
                pinctrl-single,pins = <
                    J721S2_IOPAD(0x0A4, PIN_INPUT_PULLDOWN, 7) /* P9.18 GPIO0_40 */
                >;
            };
        };
    };

    fragment@2 {
        target-path = "/";
        __overlay__ {
            gps_pps {
                status = "okay";
                compatible = "pps-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <&bb_gps_pps_pins>;
                gpios = <&gpio0 40 0>; //refer https://docs.beagleboard.org/latest/boards/beaglebone/ai-64/ch07.html p9.18 row gpio
            };
        };
    };
};

I have tried to exchange the BBB specific values with the values for BBAI64. e.g:

am33xx_pinmux                                               -> main_pmx0
P9.12                                                       -> P9.18
compatible = "ti,beaglebone-black";                         -> compatible = "beagle,j721e-beagleboneai64", "ti,j721e";
BONE_P9_12 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio1_28 */  -> J721S2_IOPAD(0x0A4, PIN_INPUT_PULLDOWN, 7) /* P9.18 GPIO0_40 */
gpios = <&gpio1 28 0>;                                      -> gpios = <&gpio0 40 0>;

In order to build and install the files I have used the following commands:

git clone https://github.com/beagleboard/BeagleBoard-DeviceTrees/tree/v5.10.x-ti-arm64
cd BeagleBoard-DeviceTrees
# change to specific kernel version and architecture (can be acquired with uname -a)
git checkout v5.10.x-ti-arm64
cd src/arm64/overlays/ 
#create the new overlay. e.g.: vim BBAI64-P9_18-GPS-PPS.dts
#insert code into the new overlay
cd ../../../
make clean
make
sudo make install

In order to activate the overlay I have changed the contents of /boot/firmware/extlinux/extlinux.conf to:

label Linux eMMC
    kernel /Image
    append root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait net.ifnames=0 quiet
    fdtdir /
    fdtoverlays /overlays/BONE-UART1.dtbo /overlays/BBAI64-P9_18-GPS-PPS.dtbo
    initrd /initrd.img

Currently running Kernel: 5.10.162-ti-arm64-r96

Little Update: Reducing the dts to the following lets me boot BBAI-64 succesfully.
bbai64-gps-pps.dts (1.5 KB)

However because fragment@2 is commented out pps is not working.

fragment@X present β€œx” means the block was commented out.
fragment@X present β€œy” means the block was not commented out.
I have tried the following configurations and only fragment@1 seems to work fine:

fragment@0 present fragment@1 present fragment@2 present bootable
x x x y
y x x x
x y x y Uploaded example
x y y x
x x y x

I am also not an expert and usually have some trouble with device trees.

I have never used fragment and overlay.
Generally to change something in a define part I would do the following.

&main_mcan0 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&main_mcan0_pins_default >;
};

No fragment or overlay. However not sure of the syntax if you are adding something that doesn’t already exist.

I would first try something like this

/dts-v1/;
/plugin/;

#include <dt-bindings/board/k3-j721e-bone-pins.h>   /*<- #include <dt-bindings/board/am335x-bbw-bbb-base.h>*/
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/k3.h>                 /*<- #include <dt-bindings/pinctrl/am33xx.h> */

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */

&{/chosen} {
   overlays {
      BB-UART-GPS =  __TIMESTAMP__;;
   };
};



&main_pmx0 {
   bb_gps_pps_pins: pinmux_bb_gps_pps_pins {
      pinctrl-single,pins = <
      J721S2_IOPAD(0x0A4, PIN_INPUT_PULLDOWN, 7) /* P9.18 GPIO0_40 */
      >;
   };
   
};

&ocp{
      P9_18_pinmux{status="disabled";};
}


&/{
   gps_pps {
      status = "okay";
      compatible = "pps-gpio";
      pinctrl-names = "default";
      pinctrl-0 = <&bb_gps_pps_pins>;
      gpios = <&gpio0 40 0>; //refer https://docs.beagleboard.org/latest/boards/beaglebone/ai-64/ch07.html p9.18 row gpio
   };
}

But not sure about the β€œ&/{” section. If u-boot can’t do the overlay, it should at least still boot.

Hi, thanks for the different example.
I tried to compile it but it seems to fail at the β€œ&/” Node. I had to change it to β€œ&{/}”, add a β€œ;” at the end and remove the additional β€œ;” from the timestamp line. I will see now if that works.

/dts-v1/;
/plugin/;

#include <dt-bindings/board/k3-j721e-bone-pins.h>   /*<- #include <dt-bindings/board/am335x-bbw-bbb-base.h>*/
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/k3.h>                 /*<- #include <dt-bindings/pinctrl/am33xx.h> */

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */

&{/chosen} {
   overlays {
      BB-UART-GPS =  __TIMESTAMP__;
   };
};

&main_pmx0 {
   bb_gps_pps_pins: pinmux_bb_gps_pps_pins {
      pinctrl-single,pins = <
      J721S2_IOPAD(0x0A4, PIN_INPUT_PULLDOWN, 7) /* P9.18 GPIO0_40 */
      >;
   };

};

&ocp{
      P9_18_pinmux{status="disabled";};
};

&{/} {
   gps_pps {
      status = "okay";
      compatible = "pps-gpio";
      pinctrl-names = "default";
      pinctrl-0 = <&bb_gps_pps_pins>;
      gpios = <&gpio0 40 0>; //refer https://docs.beagleboard.org/latest/boards/beaglebone/ai-64/ch07.html p9.18 row gpio
   };
};

The latest example is still unable to boot.
Additionally, I dont think the P9_18_pinmux node exists for BBAI64 since I cant find any reference for it in the BeagleBone Kernel Code in the branch β€œ5.10.162-ti-arm64-r96” that I am currently using. (Every reference I can find is for the arm architecture and not arm64 so I dont think these reference apply for BBAI64)
Commenting that out and recompiling is still unable to boot.

Is there any way to debug the boot process?

I have added the decompiled version of the device tree with and without using the ocp node if anyone would need to have a look at that. I used the following command to decompile the generated .dtbo files:

dtc -I dtb -O dts BBAI64-P9_18-GPS-PPS.dtbo -o /tmp/BBAI64-P9_18-GPS-PPS.dts 

BBAI64-P9_18-GPS-PPS-WITH-OCP.dts (1.1 KB)
BBAI64-P9_18-GPS-PPS-WITHOUT-OCP.dts (926 Bytes)

You will need a serial cable, 3V ttl with a tiny pitch connector, just to the side of the USB C connector.

I am not sure you need the OCP section.

By default P9_18 is configured as GPIO 0.40 input and GPIO0.120 input.
That header pin connects to 2 different pads on the processor.

Looking through the device tress I don’t think

J721S2_IOPAD(0x0A4, PIN_INPUT_PULLDOWN, 7) /* P9.18 GPIO0_40 */

Is correct. If you look in /include/dt-bindings/board/k3-j721e-bone-pins.h

You can see they use a J721E_IOPAD macro not with an S. It is possible you are setting a completely different register. That could be the reason your board fails to boot.

J721E_IOPAD(0xA4, PIN_INPUT_PULLDOWN, 7)

I have applied the change from J721S2 to J721E. Booting with the overlay is still not possible. I will try to get my hand on a tiny pitch connector from work and will try to provide the information that I can get over the serial connection.

Okay, after slow but continous progress of the boot process over serial I have let the BBAI64 boot for longer than usual. The heartbeat leds blinked a few times before the whole thing crashed. Here is the complete data from the serial connection.
BBAI64-u-boot.log (66.4 KB)
I used minicom and added additional timing information.

The following lines from the log show that the overlay is not applied:

...
[2023-03-21 17:59:49] Retrieving file: /overlays/BBAI64-P9_18-GPS-PPS-BENEDICT.dtbo
[2023-03-21 17:59:49] 919 bytes read in 8 ms (111.3 KiB/s)
[2023-03-21 17:59:49] failed on fdt_overlay_apply(): FDT_ERR_NOTFOUND
[2023-03-21 17:59:49] Failed to apply overlay /overlays/BBAI64-P9_18-GPS-PPS-BENEDICT.dtbo, skipping
...

What is the log from uboot?

Is the log over uart the uboot log or is there another way to view that? I did not try to issue any commands during the process.

From the uart
.

I would imagine the part causing the problem is the gps_pps section.

You could try removing the gps_pps section and check to see of the rest of the dts file is good. That will at least narrow down the part that is causing problems.

Issue with dts files are very hard to debug.

Removing the gps_pps section and booting works fine.
The currently used dts file looks like this:

/dts-v1/;
/plugin/;

#include <dt-bindings/board/k3-j721e-bone-pins.h>   /*<- #include <dt-bindings/board/am335x-bbw-bbb-base.h>*/
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/k3.h>                 /*<- #include <dt-bindings/pinctrl/am33xx.h> */

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */

&{/chosen} {
   overlays {
      BB-UART-GPS =  __TIMESTAMP__;
   };
};

&main_pmx0 {
   bb_gps_pps_pins: pinmux_bb_gps_pps_pins {
      pinctrl-single,pins = <
      J721E_IOPAD(0xA4, PIN_INPUT_PULLDOWN, 7) /* P9.18 GPIO0_40 */
      >;
   };
};

//&ocp{
//      P9_18_pinmux{status="disabled";};
//};

//&{/} {
//   gps_pps {
//      status = "okay";
//      compatible = "pps-gpio";
//      pinctrl-names = "default";
//      pinctrl-0 = <&bb_gps_pps_pins>;
//      gpios = <&gpio0 40 0>; //refer https://docs.beagleboard.org/latest/boards/beaglebone/ai-64/ch07.html p9.18 row gpio
//   };
//};

ok after a quick dig through the dts files, I think the issue
is with

gpios = <&gpio0 40 0>;

what you probably should have is

gpios = <&main_gpio0 40 0>;

Give that a go

1 Like

Hi, the BBAI64 now boots with the gps_pps section enabled! Thank you very much. I will write atleast one more update when I have the GPS running to see if anything else has to be configured.

1 Like

good to hear. those device trees can be real tricky.

Everything is working now. Huge thanks to Benedict again for helping me in this matter!

The final dts is here:
BBAI64-P9_18-GPS-PPS.dts (940 Bytes)

The steps to build and use the dtbo have not changed. For the sake of easy access I have copied the initial steps from my first message.
In order to build and install the files I have used the following commands

git clone https://github.com/beagleboard/BeagleBoard-DeviceTrees/tree/v5.10.x-ti-arm64
cd BeagleBoard-DeviceTrees
# change to specific kernel version and architecture (can be acquired with uname -a)
git checkout v5.10.x-ti-arm64
cd src/arm64/overlays/ 
#create the new overlay. e.g.: vim BBAI64-P9_18-GPS-PPS.dts
#insert code into the new overlay
cd ../../../
make clean
make
sudo make install

In order to activate the overlay I have changed the contents of /boot/firmware/extlinux/extlinux.conf to:

label Linux eMMC
    kernel /Image
    append root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait net.ifnames=0 quiet
    fdtdir /
    fdtoverlays /overlays/BONE-UART1.dtbo /overlays/BBAI64-P9_18-GPS-PPS.dtbo
    initrd /initrd.img
3 Likes

Newbie here! Not super clear on the muxing and i’m hoping to make this work on a BeaglePlay. Would anyone be able to help me to figure out the changes I should make to this file?

/*
* Device Tree Overlay for GPS PPS input on P9_18
*
* Based on this thread:
* https://forum.beagleboard.org/t/bbai-64-create-a-device-tree-overlay-for-gps-pps-support/34268
*/

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/k3.h>

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */

&{/chosen} {
   overlays {
      k3-am625-beagleplay-csac-PPS =  __TIMESTAMP__;
   };
};

&main_pmx0 {
   bb_gps_pps_pins: pinmux_bb_gps_pps_pins {
      pinctrl-single,pins = <
          &main_gpio1 11 0x27
        >;
   };

};

&{/} {
   gps_pps {
      status = "okay";
      compatible = "pps-gpio";
      pinctrl-names = "default";
      pinctrl-0 = <&bb_gps_pps_pins>;
      gpios = <&main_gpio1 11 0>; /* refer https://docs.beagleboard.org/latest/boards/beaglebone/ai-64/ch07.html p9.18 row 7 */
   };
};