Open main menu

DAVE Developer's Wiki β

DESK-MX8M-L/Peripherals/GPIOs

< DESK-MX8M-L
Revision as of 14:20, 14 January 2022 by U0007 (talk | contribs)

History
Version Issue Date Notes
1.0.0 Jan 2022 First DESK-MX8M release


Contents

Peripheral GPIOsEdit

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 configurationEdit

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 peripheralEdit

Linux messages at boot timeEdit

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 functionEdit

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 sysfsEdit

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 informationEdit

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

GPIO sysfs deprecatedEdit

  sysfs GPIO ABI has been deprecated. See more information here about it. A character device access has to be used, more information here  

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