gpiobeagleboneblackdevice-treedebian-buster

Simple GPIO Device Tree Example for Beaglebone Black Deb 10.3


My goal is to write a simple .dts file (to be compiled to .dtbo using DT 1.4.4) to configure a GPIO output on boot on a Beaglebone Black Rev C running Debian 10.3 I intend to place the .dtbo in /lib/firmware and then specify it in /boot/uEnv.txt

I understand some parts of the .dts file and have tried decompiling exisiting .dtbo files in /lib/firmware/ for guidance but none of them are a simple GPIO output example. A lot of online resources involve make and make install but I believe DT should be able to handle it by now right?

I was able to get the following to compile but with issue:

/* dtc -O dtb -o BB-P8_13-LED.dtbo -b 0 -@ BB-P8_13-LED-00A0.dts */

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone-black";
        /* identification */
        part-number = "BB-P8_13-LED";
        version = "00A0";

        /* state the resources this cape uses */
        exclusive-use =
                /* the pin header uses */
                "P8.13",    /* GPIO_23 */
                /* the hardware ip uses */
                "gpio23";
                
        fragment@0 {
            target = <&am33xx_pinmux>;
            __overlay__ {
                bb_gpio23_pin: pinmux_bb_gpio23_pin {
                    pinctrl-single,pins = < 0x024 0x07 >; /*P8_13 GPIO23 MODE7*/
                };
            };
        };
        
        fragment@1 {
                target = <&gpio23>;
                __overlay__ {
                    leds {
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&bb_gpio23_pin>;
                        compatible = "gpio-leds";
                        P8_13 {
                            label = "P8_13";
                            default-state = "on";
                        };
                    };
                };
        };
};

Q: Why does loading this .dtbo in /boot/uEnv.txt cause all other GPIOs to disappear from /sys/class/gpio/? I thought fragment0 was for excluding a single gpio, not all of them.

###Additional custom capes
uboot_overlay_addr4=/lib/firmware/BB-P8_13-LED-00A0.dtbo

Q: Where are the files for controlling the GPIO (for testing) or rather what can I add to my .dts file so the gpio23 still appears in /sys/class/gpio or even /sys/class/leds? Ultimately I want to be able to control this GPIO with Node-RED.

Q: Do I need to be consistent with my use of P8.13 vs. P8_13? I think I'm mixing up terminology used in .dts files that get compiled with make vs DT.

Q: I think my fragment@1 P8_13 child node is missing something to specify the gpio bank and active high/low setting. Something like "gpios = <&gpio3 19 GPIO_ACTIVE_HIGH>;" Where can I look to research which bank GPIO23 is in? What does the '19' mean in that statement?


Solution

  • The .dts file in my first answer did not fix my problem. GPIO P8_13 still boots as an input. After more digging and testing I have discovered it is NOT possible to make a GPIO direction survive a reboot. It will always boot to the default and the best you can do is enable a pullup or pulldown resistor to keep the pin high or low until a custom service file (or program) can write to /sys/class/gpio/gpioXXX/direction. I even tried decompiling am335x-boneblack.dtb, editing it, and re-compiling with no luck.

    This is sad and incredibly frustrating. What good is an output that flickers during reboot? Guess I'll have to compensate with fancy external circuitry.