DESK-MX6UL-L/Pheripherals/GPIOs

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

1.0.0

Apr 2021 First DESK release
2.0.0 Mar 2022 DESK 3.0.0 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-lynx:~# ls -la /sys/class/leds/
total 0
drwxr-xr-x  2 root root 0 Mar 24 10:25 .
drwxr-xr-x 54 root root 0 Mar 24 10:25 ..
lrwxrwxrwx  1 root root 0 Mar 24 10:25 gpio113 -> ../../devices/platform/uart8_rs232/leds/gpio113
lrwxrwxrwx  1 root root 0 Mar 24 10:25 gpio114 -> ../../devices/platform/uart3_rs485/leds/gpio114
lrwxrwxrwx  1 root root 0 Mar 24 10:25 gpio136 -> ../../devices/platform/uart8_rs232/leds/gpio136
lrwxrwxrwx  1 root root 0 Mar 24 10:25 gpio137 -> ../../devices/platform/uart8_rs232/leds/gpio137
lrwxrwxrwx  1 root root 0 Mar 24 10:25 mmc0:: -> ../../devices/platform/soc/2100000.bus/2190000.mmc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Mar 24 10:25 mmc1:: -> ../../devices/platform/soc/2100000.bus/2194000.mmc/leds/mmc1::

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-lynx:~# echo 1 > /sys/class/gpio/export
root@desk-mx6ul-lynx:~# echo out > /sys/class/gpio/gpio1/direction
root@desk-mx6ul-lynx:~# echo 1 > /sys/class/gpio/gpio1/value
root@desk-mx6ul-lynx:~#
  • 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-lynx:~# echo 2 > /sys/class/gpio/export
root@desk-mx6ul-lynx:~# echo in > /sys/class/gpio/gpio2/direction
root@desk-mx6ul-lynx:~# cat /sys/class/gpio/gpio2/value
0

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