DESK-MX8M-L/Peripherals/GPIOs

From DAVE Developer's Wiki
Jump to: navigation, search
History
Version Issue Date Notes
1.0.0 Jan 2022 First DESK-MX8M release


Peripheral GPIOs[edit | edit source]

i.MX8 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.

Device tree configuration[edit | edit source]

Here below a simple example of device tree configuration for using a GPIO on DAVE's kit for the ORCA SOM with gpio-leds sysfs interface:

From imx8mp-mito8mplus-cb1001.dts:

       leds {
       compatible = "gpio-leds";

       gpio-test {
               gpios = <&gpio4 24 GPIO_ACTIVE_HIGH>;
               default-state = "off";
           };
       };
...
...
&iomuxc {
       pinctrl-names = "default";
       pinctrl-0 = <&pinctrl_hog>;

       pinctrl_hog: hoggrp {
        fsl,pins = <
                       MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24 0x19
        >;
    };
};

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-mx8mp:~# ls -la /sys/class/leds/
total 0
drwxr-xr-x  2 root root 0 Jan 14 12:08 .
drwxr-xr-x 82 root root 0 Jan 14 12:08 ..
lrwxrwxrwx  1 root root 0 Jan 14 12:08 gpio-test -> ../../devices/platform/leds/leds/gpio-test
lrwxrwxrwx  1 root root 0 Jan 14 12:08 mmc0:: -> ../../devices/platform/soc@0/30800000.bus/30b40000.mmc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Jan 14 12:08 mmc1:: -> ../../devices/platform/soc@0/30800000.bus/30b50000.mmc/leds/mmc1::
lrwxrwxrwx  1 root root 0 Jan 14 12:08 mmc2:: -> ../../devices/platform/soc@0/30800000.bus/30b60000.mmc/leds/mmc2::
root@desk-mx8mp:~#

Usage as led function[edit | edit source]

Setting the brightness node, it is possible to change the GPIO status:

  • read actual led/GPIO status
root@desk-mx8mp:~# cat /sys/class/leds/gpio-test/brightness
0
root@desk-mx8mp:~#
  • change led/GPIO status to High (1)
root@desk-mx8mp:~# echo 1 > /sys/class/leds/gpio-test/brightness

Usage with sysfs[edit | edit source]

It is possible to configure the GPIO pin directly at Linux userspace using sysfs even if it is discouraged: see below .

See here below, an example of configuring a GPIO pin using J8 connector:

  • set J8.11 SAI2_RXD0 (MX8MP_IOMUXC_SAI2_RXD0__GPIO4_IO23) as output GPIO
    • GPIO4_IO23 => (n-1)*32 + IO = (4-1)*32+23 = 119
  • export the GPIO
root@desk-mx8mp:~# echo 119 > /sys/class/gpio/export

Using the GPIO as output

root@desk-mx8mp:~# echo out > /sys/class/gpio/gpio119/direction
  • set the GPIO level
root@desk-mx8mp:~# echo 1 > /sys/class/gpio/gpio119/value

For using the GPIO as input:

root@desk-mx8mp:~# echo in > /sys/class/gpio/gpio119/direction
  • read the GPIO level
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value
1
root@desk-mx8mp:~#

Note that on i.MX SoC the GPIO value can be read back only if the SION bit is set the pin muxing.

Additional information[edit | edit source]

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

GPIO sysfs deprecated[edit | edit source]

Warning-icon.png sysfs GPIO ABI has been deprecated. See 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