So I want to control some GPIO pins using the Gpio
class.
I've written the following device tree overlay (
/opt/bb.org-overlays/src/arm/BB-WARD-00A0.dts
) to make the pins accessible as GPIO outputs
/* 2022, Ward Slager */
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";
// Free pins used by the pinmux helpers
fragment@0 {
target = <&ocp>;
__overlay {
P8_38_pinmux { status = "disabled"; }; // gate 3
P8_39_pinmux { status = "disabled"; }; // gate 4
P8_40_pinmux { status = "disabled"; }; // gate 5
P9_20_pinmux { status = "disabled"; }; // OLED SPI CS
P9_23_pinmux { status = "disabled"; }; // OLED SPI DC
P9_17_pinmux { status = "disabled"; }; // ADC SPI CS A
P9_15_pinmux { status = "disabled"; }; // ADC SPI CS B
};
};
// Free pins used by i2c2 (BELA)
fragment@1 {
target = <&i2c2>;
__overlay {
status = "disabled";
};
};
// Configure pins so that they can be used by the Gpio library
fragment@2 {
target = <&am33xx_pinmux>;
__overlay {
bb_ward_gpio_pins: pinmux_bb_ward_gpio_pins {
pinctrl-single,pins = <
0x8C4 0x17 /* P8.38, all set to GPIO output pullup */
0x8B8 0x17 /* P8.39 */
0x8BC 0x17 /* P8.40 */
0x978 0x17 /* P9.20 */
0x844 0x17 /* P9.23 */
0x95C 0x17 /* P9.17 */
0x840 0x17 /* P9.15 */
>;
};
};
};
fragment@3 {
target-path = "/";
__overlay {
ward_gpio_pins {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&bb_ward_gpio_pins>;
};
};
};
};
I compiled the file and ran the install.sh script in bb.org-overlays so the dtbo is placed in /lib/firmware/
Then I added the file to uEnv.txt
which looks like this:
uenvcmd=echo loading ${fdtfile}; load mmc ${mmcid}:2 ${fdtaddr} boot/dtbs/${uname_r}/${fdtfile}; if env exists uboot_overlay_addr0; then setenv overlay ${uboot_overlay_addr0}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr1; then setenv overlay ${uboot_overlay_addr1}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr2; then setenv overlay ${uboot_overlay_addr2}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr3; then setenv overlay ${uboot_overlay_addr3}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr4; then setenv overlay ${uboot_overlay_addr4}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr5; then setenv overlay ${uboot_overlay_addr5}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr6; then setenv overlay ${uboot_overlay_addr6}; run bela_loadoverlay; fi; if env exists uboot_overlay_addr7; then setenv overlay ${uboot_overlay_addr7}; run bela_loadoverlay; fi; load mmc ${mmcid}:2 ${loadaddr} /boot/vmlinuz-${uname_r}; setenv bootargs console=${console} root=/dev/mmcblk${mmcid}p2 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet; bootz ${loadaddr} - ${fdtaddr};
bela_loadoverlay=echo loading ${overlay}; load mmc ${mmcid}:2 ${rdaddr} ${overlay}; fdt addr $fdtaddr; fdt resize 0x60000; fdt apply ${rdaddr}; fdt resize 0x60000;
uboot_overlay_addr2=/lib/firmware/BB-BELA-00A1.dtbo
uboot_overlay_addr3=/lib/firmware/BB-BELA-CTAG-SPI-00A0.dtbo
uboot_overlay_addr4=/lib/firmware/BB-SPIDEV0-00A0.dtbo
uboot_overlay=addr5=/lib/firmware/BB-WARD-00A0.dtbo
console=ttyS0,115200n8
uname_r=4.14.108-ti-xenomai-r143
mmcid=1
Inside render.cpp:
void setup()
{
// (...)
gateOUT[0].open(pinGpioGate3, Gpio::OUTPUT);
gateOUT[1].open(pinGpioGate4, Gpio::OUTPUT);
gateOUT[2].open(pinGpioGate5, Gpio::OUTPUT);
// (...)
}
void render(BelaContext *context, void *userData)
{
if ((gFrame % 256) > 128)
{
gateOUT[0].set();
gateOUT[1].set();
gateOUT[2].set();
}
else
{
gateOUT[0].clear();
gateOUT[1].clear();
gateOUT[2].clear();
}
gFrame++;
}
The compilation of the .dts
file gave no errors, and the Beaglebone works. When hit run the .open() function even returns 0 but still calling .write() does not change the GPIO voltage..