BeaglePlay disable Mikrobus to free GPIO pin

Hi,
I just bought a BeaglePlay to be used with HomeAssistant.
Now I would like to use the GPIO (mikrobus) pin to drive an external relay but the pins are used by Mikrobus driver.

gpioinfo command indicate the pins are used by mikrobus:

||line   7: MIKROBUS_GPIO1_7 mikrobus output active-high [used]|
|---|---|
||line   8: MIKROBUS_GPIO1_8 mikrobus output active-high [used]|
||line   9: MIKROBUS_GPIO1_9 mikrobus output active-high [used]|
||line  10: MIKROBUS_GPIO1_10 mikrobus output active-high [used]|
||line  11: MIKROBUS_GPIO1_11 mikrobus output active-high [used]|
||line  12: MIKROBUS_GPIO1_12 mikrobus output active-high [used]|
||line  13: MIKROBUS_W1_GPIO0 w1-gpio.0 output active-high [used open-drain]|
||line  14: MIKROBUS_GPIO1_14 mikrobus output active-high [used]|

I flashed this image on the eMMC:

Is there a way to free up the GPIO pins and disable Mikrobus driver?

Thanks

Ok, don’t know if it’s the best solution because I got it from Copilot but it works…

vi /boot/firmware/overlays/disable-mikrobus.dts

add this content:

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,am625-beagleplay";

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

build it:

dtc -I dts -O dtb -o /boot/firmware/overlays/disable-mikrobus.dtbo /boot/firmware/overlays/disable-mikrobus.dts
vi /boot/firmware/extlinux/extlinux.conf

Modify the last part as follow:

label BeaglePlay eMMC (default)
    kernel /Image
    append root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait net.ifnames=0 systemd.unified_cgroup_hierarchy=false quiet
    fdtdir /
    #fdtoverlays /overlays/<file>.dtbo
    initrd /initrd.img
    fdtoverlays /overlays/disable-mikrobus.dtbo

After a reboot I can see all the Mikrobus GPIO free and usable…

Not sure what the problem is but now I can use GPIO this way:

echo 318 > /sys/class/gpio/gpiochip311/subsystem/export
echo out > /sys/class/gpio/gpiochip311/subsystem/gpio318/direction
echo 1 > /sys/class/gpio/gpiochip311/subsystem/gpio318/value

only the first time I reboot after removed Mikrobus.
When I remove power and restart, the GPIO is not responsive anymore until I re-enable Mikrobus and remove again…

sudo apt update && sudo apt upgrade -y
sudo apt install libgpiod-dev gpiod

sudo apt install python3-libgpiod

$ sudo usermod -aG gpio $USER
$ sudo newgrp gpio
$ gpioinfo

All the package are installed.
This is gpioinfo output with Mikrobus driver enabled:

gpiochip3 - 88 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:   "SPE_RSTN"  "PHY reset"  output   active-low [used]
	line   6:   "SPE_INTN"       unused   input  active-high 
	line   7: "MIKROBUS_GPIO1_7" "mikrobus" output active-high [used]
	line   8: "MIKROBUS_GPIO1_8" "mikrobus" output active-high [used]
	line   9: "MIKROBUS_GPIO1_9" "mikrobus" output active-high [used]
	line  10: "MIKROBUS_GPIO1_10" "mikrobus" output active-high [used]
	line  11: "MIKROBUS_GPIO1_11" "mikrobus" output active-high [used]
	line  12: "MIKROBUS_GPIO1_12" "mikrobus" output active-high [used]
	line  13: "MIKROBUS_W1_GPIO0" "w1-gpio.0" output active-high [used open-drain]
	line  14: "MIKROBUS_GPIO1_14" "mikrobus" output active-high [used]
	line  15:      unnamed       unused   input  active-high 
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19: "VDD_3V3_SD" "regulator-4" output active-high [used]
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22: "MIKROBUS_GPIO1_22" "mikrobus" output active-high [used]
	line  23: "MIKROBUS_GPIO1_23" "mikrobus" output active-high [used]
	line  24: "MIKROBUS_GPIO1_24" "mikrobus" output active-high [used]
	line  25: "MIKROBUS_GPIO1_25" "mikrobus" output active-high [used]

Now if I try to access MIKROBUS_GPIO1_7 pin I get an error:

root@BeaglePlay:/home/debian# echo 318  >  /sys/class/gpio/gpiochip311/subsystem/export 
bash: echo: write error: Device or resource busy

an it’s OK because it’s used by mikrobus layer.

Then I disable the Mikrobus layer as explained before by editing /boot/firmware/extlinux/extlinux.conf and reboot using reboot command without unplugging power from the board.

Now the output of gpioinfo is:

gpiochip3 - 88 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:   "SPE_RSTN"  "PHY reset"  output   active-low [used]
	line   6:   "SPE_INTN"       unused   input  active-high 
	line   7: "MIKROBUS_GPIO1_7" unused input active-high 
	line   8: "MIKROBUS_GPIO1_8" unused input active-high 
	line   9: "MIKROBUS_GPIO1_9" unused input active-high 
	line  10: "MIKROBUS_GPIO1_10" unused input active-high 
	line  11: "MIKROBUS_GPIO1_11" unused input active-high 
	line  12: "MIKROBUS_GPIO1_12" unused input active-high 
	line  13: "MIKROBUS_W1_GPIO0" unused input active-high 
	line  14: "MIKROBUS_GPIO1_14" unused input active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19: "VDD_3V3_SD" "regulator-4" output active-high [used]
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22: "MIKROBUS_GPIO1_22" unused input active-high 
	line  23: "MIKROBUS_GPIO1_23" unused input active-high 
	line  24: "MIKROBUS_GPIO1_24" unused input active-high 
	line  25: "MIKROBUS_GPIO1_25" unused input active-high

and the output indicates MIKROBUS_GPIO1_7 is unused (as expected).

Now I can access the GPIO:

root@BeaglePlay:/home/debian# echo 318  >  /sys/class/gpio/gpiochip311/subsystem/export 
root@BeaglePlay:/home/debian# echo out >  /sys/class/gpio/gpiochip311/subsystem/gpio318/direction
root@BeaglePlay:/home/debian# cat  /sys/class/gpio/gpiochip311/subsystem/gpio318/value
0
root@BeaglePlay:/home/debian# echo 1 >  /sys/class/gpio/gpiochip311/subsystem/gpio318/value
root@BeaglePlay:/home/debian# cat  /sys/class/gpio/gpiochip311/subsystem/gpio318/value
1

As you can see I can change the value and read it. And it works for every reboot using reboot command.

Now If I halt the board, unplug the power and restart it, GPIO stop responding:

root@BeaglePlay:/home/debian# echo 318  >  /sys/class/gpio/gpiochip311/subsystem/export 
root@BeaglePlay:/home/debian# echo out >  /sys/class/gpio/gpiochip311/subsystem/gpio318/direction
root@BeaglePlay:/home/debian# cat  /sys/class/gpio/gpiochip311/subsystem/gpio318/value
0
root@BeaglePlay:/home/debian# echo 1 >  /sys/class/gpio/gpiochip311/subsystem/gpio318/value
root@BeaglePlay:/home/debian# cat  /sys/class/gpio/gpiochip311/subsystem/gpio318/value
0

As you can see, even if I put value 1 on the GPIO, when I read it its value is still 0 .

To reenable GPIO I have to redo all the steps by enabling Mikrobus, disabling it and so on…

In my opinion there is some initialization the mikrobus layer do. That initialization resets when unplugging the board.

Any help is appreciated.

Thanks!

I haven’t got a BeaglePlay, but my best guess would be that the Mikrobus stuffs set the pinmuxing for the GPIO pins. Just doing a reboot probably doesn’t change that, so your code then works after disabling Mikrobus.

But a power cycle will reset the pinmuxing to whatever the chip default is and probably this is not as GPIO so your code then fails.

If that is the case, what you will need to do is to create your own overlay that sets the correct pinmuxing for the pin you want to use and load that. Maybe such an overlay already exists which would make things easier.

Thanks, that’s could be the reason but I’m not very familiar with overlays.

How can I find the one for my case?

Usually the source for these is in /opt/source/dir_with_kernel_version/
I can’t remember exactly. It could also be that you need to git clone a repo to get them. @RobertCNelson would be able to tell you.

If all you need is an output, there is possibly an LED definition provided that you would just need to enable. This would allow access to the GPIO pin in /sys/class/led somewhere. I think there are also definitions for a ‘key’ that would provide input functionality.

Thanks Benedict,
after you suggestion I checked on overlays directory:

root@BeaglePlay:/home/debian# ls /boot/firmware/overlays/
BB-I2C2-MPU6050.dtbo		 BONE-I2C4.dtbo		BPLAY-CSI-ov5647.dtbo
BBAI64-CSI0-imx219.dtbo		 BONE-LED_P8_03.dtbo	J721E-PRU-UIO-00A0.dtbo
BBAI64-CSI1-imx219.dtbo		 BONE-LED_P9_11.dtbo	disable-mikrobus.dtbo
BBAI64-DSI-RPi-7inch-panel.dtbo  BONE-LED_P9_14.dtbo	BBAI64-P8_37-ehrpwm5_a.dtbo	 BONE-PWM0.dtbo		k3-am625-beagleplay-bcfserial-no-firmware.dtbo
BBAI64-P9_25-ehrpwm4_b.dtbo	 BONE-PWM1.dtbo		k3-am625-beagleplay-csi2-ov5640.dtbo
BBORG_LOAD-00A2.dtbo		 BONE-PWM2.dtbo		k3-am625-beagleplay-lt-lcd185.dtbo
BBORG_RELAY-00A2.dtbo		 BONE-SPI0_0.dtbo	k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo
BBORG_SERVO-00A2.dtbo		 BONE-SPI0_1.dtbo	k3-am625-beagleplay-release-mikrobus.dtbo
BONE-FAN.dtbo			 BONE-SPI1_0.dtbo	k3-j721e-beagleboneai64-RPi-7inch-panel.dtbo
BONE-I2C1.dtbo			 BONE-UART1.dtbo	robotics-cape-spitest.dtbo
BONE-I2C2.dtbo			 BONE-USB0-host.dtbo	robotics-cape.dtbo
BONE-I2C3.dtbo			 BPLAY-CSI-ov5640.dtbo

and I noted this: k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo

Then I added to extlinux.conf:

label BeaglePlay eMMC (default)
    kernel /Image
    append root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait net.ifnames=0 systemd.unified_cgroup_hierarchy=false quiet
    fdtdir /
    #fdtoverlays /overlays/<file>.dtbo
    initrd /initrd.img
    fdtoverlays /overlays/k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo

And now GPIO keep responding after a complete poweroff.

It was that simple!

Thanks a lot!

Glad to have helped.