Switching the user_led on and off - FrankBau/meta-marsboard-bsp GitHub Wiki

Prerequisites:

  • Linux boots on the MarS Board

This is a very easy task because the user_led (a green LED near pin1 of header J10) is already defined in the device tree. Boot Linux, login as root (no password) and enter:

echo 1 > /sys/class/leds/user_led/brightness 
echo 0 > /sys/class/leds/user_led/brightness 

which will toggle the user LED. Now, check the device tree file which is fsl-community-bsp/build/tmp/work/marsboard-poky-linux-gnueabi/linux-marsboard/3.10.17-r0/git/arch/arm/boot/dts/imx6q-marsboard.dts:

leds { /* see iomuxc definition below */
    compatible = "gpio-leds";
    sys_led {
        gpios = <&gpio3 28 GPIO_ACTIVE_LOW>;
        linux,default-trigger = "heartbeat";
    };
    user_led {
        gpios = <&gpio5 2 GPIO_ACTIVE_LOW>;
    };
};

To better understand this, you should check MarSBoard schematics for "USER LED": find pad name EIM_D28 on page 15. Note: EIM_A25 is the sys_led tied to linux heartbeat. It is not obvious from the schematics which is which.

Now, check for EIM_D28 pad in the iMX6 Reference Manual. You will see several modes in which this pin can be put. ALT5 is the GPIO function (ALT5 GPIO5_IO2). From the device tree you know that the pad is in GPIO Mode (ALT5).

iMX6 GPIOs come in groups of 32 pins each. The user LED is in Group gpio5 pin 2. From this you can calculate the pin number needed sometimes by Linux.

pin_nr = (group-1) *32 + pin, i.e. pin_nr = (5-1)*32+2 = 130.

The same device tree file references the GPIOs again here:

&iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_hog>;

	hog {
		pinctrl_hog: hoggrp {
		fsl,pins = < 
			/* RIoT board ?! */
			MX6QDL_PAD_GPIO_2__GPIO1_IO02 0x80000000 /* SD2 WP */
			MX6QDL_PAD_GPIO_4__GPIO1_IO04 0x80000000 /* SD2 CD */

			/* gpio-leds */
			MX6QDL_PAD_EIM_D28__GPIO3_IO28 0x80000000
			MX6QDL_PAD_EIM_A25__GPIO5_IO02 0x80000000
		>;
		};
	};
};

The value MX6QDL_PAD_EIM_A25__GPIO5_IO02 defines the function of iMX6 pad PAD_EIM_A25 as a GPIO5_IO02 (GPIO group 5 pin 2) which is function ALT5 of that pad, see iMX6 reference manual.

0x80000000 defines the pad output driver parameter. The special value 0x80000000 is for: "dont change pad output driver" which is okay in this case.

The device tree is

  • compiled by a special compiler to the binary imx6q-marsboard.dtb file (device tree blob)
  • included in the boot partition of the boot device (microSD card) and
  • loaded to memory by the U-Boot boot loader
  • read by the linux kernel which installs appropriate platform device drivers

Free online book "Device Tree for Dummies" by Thomas Petazzoni: http://events.linuxfoundation.org/sites/events/files/slides/petazzoni-device-tree-dummies.pdf

Next you might want to define your own pin on the MarS board header, connect an external LED and modify the device tree to make use of it.