DESK-MX6UL-L/Peripherals/GPIOs

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes

2021/07/20

First DESK-MX6UL-L release

2022/03/16

DESK-MX6UL-L 3.0.0 release

2023/05/04

DESK-MX6UL-L 4.0.0 release
2024/08/07 DESK-MX6UL-L 4.2.x release


Peripheral GPIOs[edit | edit source]

i.MX6UL can handle external pins in many different ways and most of them can be configured as GPIOs. When a pin is set as a GPIO, it is possible to read its value, change its direction or change output value directly from the shell.


200px-Emblem-important.svg.png

There aren't GPIOs configured in the AXEL ULite EVK

Here below an example of GPIOs usage in the i.MX6UL standard product RIALTO SBC

Device tree configuration[edit | edit source]

RIALTO SBC[edit | edit source]

Here below is an example of device tree configuration for using the:

  • RS-485 GPIOs
  • Relè
  • GPIO Push Button on Mezzanine Board
  • LEDs on Mezzanine Board

From imx6ul-lynx-som0022-cb0090.dts:

...
...
	leds {
		compatible = "gpio-leds";
		can_term {
			label = "can_term";
			gpios = <&gpio3 3 0>;
			default-state = "off";
		};

		uart2_en {
			label = "uart2_en";
			gpios = <&gpio1 22 0>;
			default-state = "on";
		};

		uart5_en {
			label = "uart5_en";
			gpios = <&gpio1 23 0>;
			default-state = "on";
		};
...
...
gpio-push-button {
		compatible = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_push_button>;
		status = "okay";
		f1 {
			label = "GPIO F1";
			gpios = <&gpio3 1 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_F1>;
		};
	};

};
...
...

&i2c2 {
	status = "okay";
...
...
	pca9551@60 {
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_pca60>;
		compatible = "nxp,pca9551";
		reg = <0x60>;
		#address-cells = <1>;
		#size-cells = <0>;
		reset-gpios = <&gpio3 22 GPIO_ACTIVE_LOW>;

		led@4 {
			label = "led2";
			reg = <4>;
			retain-state-shutdown;
			default-state = "keep";
			type = <PCA955X_TYPE_LED>;
		};

		led@5 {
			label = "led1";
			reg = <5>;
			retain-state-shutdown;
			default-state = "keep";
			type = <PCA955X_TYPE_LED>;
		};
	};
...
...
};
...
...
&iomuxc {
...
...
	imx6ul-lynx {
		pinctrl_hog_gpios: hoggrp-gpios {
			fsl,pins = <
				MX6UL_PAD_GPIO1_IO08__WDOG1_WDOG_B	0x0b0b1		/* WD RESET */
				MX6UL_PAD_GPIO1_IO01__GPIO1_IO01	0x1b0b1
				MX6UL_PAD_GPIO1_IO02__GPIO1_IO02	0x4001b0b1	/* Enable SION bit */
				MX6UL_PAD_GPIO1_IO03__GPIO1_IO03	0x4001b0b1	/* Enable SION bit */
				MX6UL_PAD_CSI_DATA04__GPIO4_IO25	0x1b0b1
				MX6UL_PAD_CSI_DATA05__GPIO4_IO26	0x1b0b1
				MX6UL_PAD_CSI_DATA06__GPIO4_IO27	0x1b0b1
				MX6UL_PAD_LCD_VSYNC__GPIO3_IO03		0x1b0b1 /* FlexCAN SW Termination */
				MX6UL_PAD_LCD_HSYNC__GPIO3_IO02		0x1b0b1 /* UART3 RS485 SW Termination */
				MX6UL_PAD_UART2_CTS_B__GPIO1_IO22	0x1b0b1 /* UART2 RS485 on RTIN enable */
				MX6UL_PAD_UART2_RTS_B__GPIO1_IO23	0x1b0b1 /* UART5 RS485 on RTIN enable */
			>;
		};

		pinctrl_gpio_push_button: gpio_push_button {
			fsl,pins = <
				MX6UL_PAD_LCD_RESET__GPIO3_IO04		0x1b0b0		/*KEY1*/
				MX6UL_PAD_LCD_ENABLE__GPIO3_IO01	0x1b0b0		/*KEY0*/
			>;
		};

...
...
};

Accessing the peripheral in RIALTO SBC[edit | edit source]

Using LEDs on Mezzanine Board[edit | edit source]

To blink LED1 on Mezzanine Board send the following commands

root@desk-mx6ul-rialto:~# echo 255 > /sys/class/leds/pca955x\:led1/brightness
root@desk-mx6ul-rialto:~# echo 0 > /sys/class/leds/pca955x\:led1/brightness
</pre>

To blink LED2 on Mezzanine Board send the following commands
<pre>
root@desk-mx6ul-rialto:~# echo 255 > /sys/class/leds/pca955x\:led2/brightness
root@desk-mx6ul-rialto:~# echo 0 > /sys/class/leds/pca955x\:led2/brightness

Using GPIO Push Button on Mezzanine Board[edit | edit source]

Pressing the Button generates the following event

root@desk-mx6ul-rialto:~# evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-push-button"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 59 (KEY_F1)
Properties:
Testing ... (interrupt to exit)
[ 5332.805492] evbug: Event. Dev: input0, Type: 1, Code: 59, Value: 1
[ 5332.811800] evbug: Event. Dev: input0, Type: 0, Code: 0, Value: 0
Event: time 1651181469.356509, type 1 (EV_KEY), code 59 (KEY_F1), value 1
Event: time 1651181469.356509, -------------- SYN_REPORT ------------
[ 5333.103596] evbug: Event. Dev: input0, Type: 1, Code: 59, Value: 0
[ 5333.109908] evbug: Event. Dev: input0, Type: 0, Code: 0, Value: 0
Event: time 1651181469.654611, type 1 (EV_KEY), code 59 (KEY_F1), value 0
Event: time 1651181469.654611, -------------- SYN_REPORT ------------

Using Relé on RTIN add-on[edit | edit source]

  • set GPIO1_IO01 as output GPIO
    • GPIO1_IO01 => (n-1)*32 + IO = (1-1)*32+1 = 1
    • to enable and disable relè, with sysfs, use the command here below
      root@desk-mx6ul-rialto:~# echo 1 > /sys/class/gpio/export
      root@desk-mx6ul-rialto:~# echo out > /sys/class/gpio/gpio1/direction
      root@desk-mx6ul-rialto:~# echo 1 > /sys/class/gpio/gpio1/value
      root@desk-mx6ul-rialto:~# echo 0 > /sys/class/gpio/gpio1/value
      
    • to enable and disable relè, with libgpiod, use the command here below
      root@desk-mx6ul-rialto:~# gpioset gpiochip0 1=1
      root@desk-mx6ul-rialto:~# gpioset gpiochip0 1=0
      
  • set GPIO2_IO02 as output GPIO
    • GPIO2_IO02 => (n-1)*32 + IO = (1-1)*32+2 = 2
    • to enable and disable relè, with sysfs, use the command here below
      root@desk-mx6ul-rialto:~# echo 2 > /sys/class/gpio/export
      root@desk-mx6ul-rialto:~# echo out > /sys/class/gpio/gpio2/direction
      root@desk-mx6ul-rialto:~# echo 1 > /sys/class/gpio/gpio2/value
      root@desk-mx6ul-rialto:~# echo 0 > /sys/class/gpio/gpio2/value
      
    • to enable and disable relè, with libgpiod, use the command here below
      root@desk-mx6ul-rialto:~# gpioset gpiochip0 2=1
      root@desk-mx6ul-rialto:~# gpioset gpiochip0 2=0
      

Using INPUT GPIO on RTIN add-on[edit | edit source]

A loopback HW connection is wired between relè and INPUT GPIO for testing purposes: the relè output sets the INPUT GPIO value.

The relè as shown in the previous chapter is set and then the INPUT GPIOs value is read.

  • set GPIO4_IO26 as input GPIO
    • GPIO4_IO26 => (n-1)*32 + IO = (4-1)*32+26 = 122
    • to enable input GPIO, with sysfs, use the command here below
      root@desk-mx6ul-rialto:~# echo 122 > /sys/class/gpio/export
      root@desk-mx6ul-rialto:~# echo in > /sys/class/gpio/gpio122/direction
      root@desk-mx6ul-rialto:~# cat /sys/class/gpio/gpio122/value
      1
      
    • to read value of input GPIOs with libgpiod, use the command here below
      root@desk-mx6ul-rialto:~# gpioget gpiochip3 26
      1
      
  • set GPIO4_IO27 as input GPIO
    • GPIO4_IO27 => (n-1)*32 + IO = (4-1)*32+27 = 123
    • to enable input GPIO, with sysfs, use the command here below
      root@desk-mx6ul-rialto:~# echo 123 > /sys/class/gpio/export
      root@desk-mx6ul-rialto:~# echo in > /sys/class/gpio/gpio123/direction
      root@desk-mx6ul-rialto:~# cat /sys/class/gpio/gpio123/value
      1
      
    • to read value of input GPIOs with libgpiod, use the command here below
      root@desk-mx6ul-rialto:~# gpioget gpiochip3 27
      1
      

Additional information[edit | edit source]

Information about GPIOs usage under sysfs directory https://www.kernel.org/doc/Documentation/gpio/sysfs.txt


Warning-icon.png sysfs GPIO ABI has been deprecated. Please find more information here about it. A character device access has to be used, more information here Warning-icon.png

Information about GPIOs library libgpiod - C library and tools - can be found on git.kernel.org