Troubles when adding a LED to Device Tree

Hi. First of all, thanks in advance for those who try to help me.

I’m studying about Device Trees, and I’ve chosen to use Beaglebone Green Wireless as a board to practice.
I’ve done the following steps:

  1. From u-boot serial, I’ve seen that Beaglebone green Wireless is using uses am335x-bonegreen-wireless-uboot-univ.dtb as DTB file
  2. Cloned / downloaded beaglebone Kernel (from GitHub - beagleboard/linux: The official Read Only BeagleBoard and BeagleBone kernel repository https://git.beagleboard.org/beagleboard/linux)
  3. I want to add LED at GPIO 47 ( = GPIO1_16, and accordingly to board schematic, AM33xx GPMC_A0 pin). I’ve edited am335x-bone-common.dtsi file, adding led (led6) in leds node as follows:

`

leds {
pinctrl-names = “default”;
pinctrl-0 = <&user_leds_s0>;
compatible = “gpio-leds”;
led2 {
label = “beaglebone:green:usr0”;
gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “heartbeat”;
default-state = “off”;
};
led3 {
label = “beaglebone:green:usr1”;
gpios = <&gpio1 22 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “mmc0”;
default-state = “off”;
};
led4 {
label = “beaglebone:green:usr2”;
gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “cpu0”;
default-state = “off”;
};
led5 {
label = “beaglebone:green:usr3”;
gpios = <&gpio1 24 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “mmc1”;
default-state = “off”;
};

led6 {
label = “beaglebone:green:extLed”;
gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “heartbeat”;
default-state = “off”;
};

};

`

And I’ve added gpio2_16 in pinmux of user leds, as follows:

`

&am33xx_pinmux {
user_leds_s0: user_leds_s0 {
pinctrl-single,pins = <
AM33XX_PADCONF(AM335X_PIN_GPMC_A5, PIN_OUTPUT_PULLDOWN, MUX_MODE7) /* gpmc_a5.gpio1_21 /
AM33XX_PADCONF(AM335X_PIN_GPMC_A6, PIN_OUTPUT_PULLUP, MUX_MODE7) /
gpmc_a6.gpio1_22 /
AM33XX_PADCONF(AM335X_PIN_GPMC_A7, PIN_OUTPUT_PULLDOWN, MUX_MODE7) /
gpmc_a7.gpio1_23 /
AM33XX_PADCONF(AM335X_PIN_GPMC_A8, PIN_OUTPUT_PULLUP, MUX_MODE7) /
gpmc_a8.gpio1_24 /
AM33XX_PADCONF(AM335X_PIN_GPMC_A0, PIN_OUTPUT_PULLUP, MUX_MODE7) /
gpmc_a0.gpio1_16 */

;
};

`

  1. I’ve successfully compiled all dtbs by doing:

`
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs

`

  1. After that, I’ve updated the recently compiled am335x-bonegreen-wireless-uboot-univ.dtb file to /boot/dtbs/{uname-r} folder in Beaglebone Green

  2. And, finally, I rebooted the board. However, board has entered in a “strange state”, with all user leds powered on. Using U-Boot serial, I’ve noticed that boot process have stopped at “starting kernel” message

In this case, what have I done wrong? Are my modifications in DTS file right?

Again, thanks in advance.

Hi!

Forget about all that device tree trouble, use libpruio instead. You can configure the pin and set the desired output state by a single function call in your programm running at user space (no sudo commands, no rebooting, …)

gpio_setValue(Io, P9_15, 1) // configure and set high

gpio_setValue(Io, P9_15, 0) // set low

You’ll have faster boot, less memory consumption, and your code executes much faster (compared with sysfs GPIO control).

You may want to check out some examples.

Regards

Your steps look right, but there is a simpler way to do them. Check out:
https://elinux.org/EBC_Exercise_17_Switching_a_GPIO_to_an_LED

No need to cross compile etc.

–Mark

Hi TJF.

I’ve never heard about libpruio before. It seems to be very nice and fast, once it uses PRUs for writing and reading I/Os, per my understanding. Thanks for the suggestion.

Best Regards,
Pedro Bertoleti

Hi Mark. Great, thanks!

Per my understanding, the Device Tree approach of https://elinux.org/EBC_Exercise_17_Switching_a_GPIO_to_an_LED doesn’t include modifying user_leds_s0 (pinmux for user leds). Do you know why isn’t this needed?

Best Regards,
Pedro Bertoleti

Pedro:
I think I got lucky and the mux was already set to gpio.

–Mark