DESK-MX6UL-L/Peripherals/GPIOs

From DAVE Developer's Wiki
Jump to: navigation, search
History
Version Issue Date Notes
1.0.0 Apr 2021 First DESK 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 GIO already configured in the AXEL ULite EVK.
Here below an example of GPIOs usage in the i.MX6UL standard product SBCLynx

Device tree configuration[edit | edit source]

Here below an example of device tree configuration for using the RS-485 GPIOs used on standard DAVE's product SBCLynx:

From imx6ul-lynx-som0013.dtsi:

        /* configure uart8/ttymxc7 as rs232 */
        uart8_rs232_config: uart8_rs232 {
                compatible = "gpio-leds";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_uart8_config>;

                status = "disabled";

                gpio113 {
                        gpios = <&gpio4 17 GPIO_ACTIVE_HIGH>;
                        default-state = "on";
                };
                gpio136 {
                        gpios = <&gpio5 8 GPIO_ACTIVE_HIGH>;
                        default-state = "on";
                };
                gpio137 {
                        gpios = <&gpio5 9 GPIO_ACTIVE_HIGH>;
                        default-state = "on";
                };
        };
};

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

        imx6ul-lynx {

...
...
                pinctrl_uart8_config: uart8grp-config {
                        fsl,pins = <
                                MX6UL_PAD_SNVS_TAMPER8__GPIO5_IO08      0x80000000 /* MPUART0_DEN */
                                MX6UL_PAD_SNVS_TAMPER9__GPIO5_IO09      0x80000000 /* MPUART0_RXEN */
                                MX6UL_PAD_CSI_MCLK__GPIO4_IO17          0x80000000 /* MPUART0_ON */
                        >;
                };

Accessing the peripheral[edit | edit source]

Linux messages at boot time[edit | edit source]

With the previous leds configuration for the GPIOs, it is possible to find them on sysfs under /sys/class/leds sub-directory:

root@desk-mx6ul-axelulite:~# ls -la /sys/class/leds/
total 0
drwxr-xr-x  2 root root 0 Apr 21 09:37 .
drwxr-xr-x 50 root root 0 Apr 21 09:37 ..
lrwxrwxrwx  1 root root 0 Apr 21 09:37 gpio113 -> ../../devices/soc0/uart8_rs232/leds/gpio113
lrwxrwxrwx  1 root root 0 Apr 21 09:37 gpio114 -> ../../devices/soc0/uart3_rs485/leds/gpio114
lrwxrwxrwx  1 root root 0 Apr 21 09:37 gpio136 -> ../../devices/soc0/uart8_rs232/leds/gpio136
lrwxrwxrwx  1 root root 0 Apr 21 09:37 gpio137 -> ../../devices/soc0/uart8_rs232/leds/gpio137
lrwxrwxrwx  1 root root 0 Apr 21 09:37 mmc0:: -> ../../devices/soc0/soc/2100000.aips-bus/2190000.usdhc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Apr 21 09:37 mmc1:: -> ../../devices/soc0/soc/2100000.aips-bus/2194000.usdhc/leds/mmc1::
root@desk-mx6ul-axelulite:~#

Usage with sysfs[edit | edit source]

  • set GPIO1_IO01 (MX6UL_PAD_GPIO1_IO01__GPIO1_IO01) as output GPIO
    • GPIO1_IO01 => (n-1)*32 + IO = (1-1)*32+1 = 1
root@desk-mx6ul-axelulite:~# echo 1 > /sys/class/gpio/export
root@desk-mx6ul-axelulite:~# echo out > /sys/class/gpio/gpio1/direction
root@desk-mx6ul-axelulite:~# echo 1 > /sys/class/gpio/gpio1/value
root@desk-mx6ul-axelulite:~#
  • set GPIO1_IO02 (echo 1 > /sys/class/gpio/gpio1/value) as input GPIO
    • GPIO1_IO02 => (n-1)*32 + IO = (1-1)*32+1 = 2
root@desk-mx6ul-axelulite:~# echo 2 > /sys/class/gpio/export
root@desk-mx6ul-axelulite:~# echo in > /sys/class/gpio/gpio2/direction
root@desk-mx6ul-axelulite:~# cat /sys/class/gpio/gpio2/value
1
root@desk-mx6ul-axelulite:~#

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. See more inofrmation 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