Difference between revisions of "DESK-MX6-L/Pheripherals/GPIOs"

From DAVE Developer's Wiki
Jump to: navigation, search
Line 11: Line 11:
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|First DESK release
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|First DESK release
 
|-
 
|-
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |{{oldid|17005|17005}}
+
| style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000" |{{oldid|17005|17005}}
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |03/03/2022
+
| style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000" |03/03/2022
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |DESK 3.0.0 release
+
| style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000" |DESK 3.0.0 release
 +
|-
 +
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |{{oldid|170xx|170xx}}
 +
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |04/10/2022
 +
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |Adding libgpiod example
 
|-
 
|-
 
|}
 
|}
Line 100: Line 104:
 
</pre>
 
</pre>
  
=== Additional information ===
+
===== Additional information =====
 
Information about GPIOs usage under sysfs directory ''https://www.kernel.org/doc/Documentation/gpio/sysfs.txt''
 
Information about GPIOs usage under sysfs directory ''https://www.kernel.org/doc/Documentation/gpio/sysfs.txt''
 +
 +
==== Usage with [https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README libgpiod] ====
  
 
{{WarningMessage|text=''sysfs'' GPIO ABI has been deprecated. See more inofrmation [https://www.kernel.org/doc/Documentation/gpio/sysfs.rst here] about it. A character device access has to be used, more information [https://embeddedbits.org/new-linux-kernel-gpio-user-space-interface/ here]}}
 
{{WarningMessage|text=''sysfs'' GPIO ABI has been deprecated. See more inofrmation [https://www.kernel.org/doc/Documentation/gpio/sysfs.rst here] about it. A character device access has to be used, more information [https://embeddedbits.org/new-linux-kernel-gpio-user-space-interface/ here]}}
  
 
Information about GPIOs library '''libgpiod''' - C library and tools - can be found on [https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ git.kernel.org]  
 
Information about GPIOs library '''libgpiod''' - C library and tools - can be found on [https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ git.kernel.org]  
 +
 +
===== libgpiod usage =====
 +
It is possible yo cross-compile <code>libgpiod</code> in the target (if the related Yocto package is not available for installation). Once the ''autoconf-archive'' package has been installed
 +
<pre>
 +
dnf install autoconf-archive
 +
</pre>
 +
 +
it is possible to clone the <code>libgpiod</code> git repository and compile the related sources:
 +
 +
<pre>
 +
git clone https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
 +
cd libgpiod
 +
./autogen.sh --enable-tools=yes --prefix=/usr/local
 +
make
 +
make install
 +
 +
Once installed, the <code>gpio</code> utilities are availabel in the target:
 +
 +
<pre class="workstation-terminal">
 +
root@desk-mx6:~# gpio
 +
gpiodetect  gpiofind    gpioget    gpioinfo    gpiomon    gpioset
 +
root@desk-mx6:~# gpio
 +
</pre>
 +
 +
===== gpio interrupt example =====
 +
If a push button, with proper pull-up, is connected to a GPIO line available - for example using the J33.34 pin available on [[AXEL_Lite_SOM/AXEL_Lite_Evaluation_Kit/Interfaces_and_Connectors/WIDE | WIDE]] connector - the related GPIO can be used as an interrupt:
 +
 +
* J33.40 is connected to J10.40 SOM pin (is J10 connector on SBC AXEL Lite EVK)
 +
** ALT-5 alternate function for this pin is GPIO1_IO06
 +
* the corresponding pin number is 0 6
 +
* <code>gpiomon</code> utility can be used for monitor the pin status and triggering, for exmaple, the 'falling-edge'' event
 +
 +
<pre class="workstation-terminal">
 +
root@desk-mx6:~# gpiomon --falling-edge 0 6
 +
event: FALLING EDGE offset: 6 timestamp: [    696.463539802]
 +
event: FALLING EDGE offset: 6 timestamp: [    696.643661944]
 +
^Croot@desk-mx6:~#
 +
</pre>
  
 
<section end="Body" />
 
<section end="Body" />

Revision as of 08:09, 4 October 2022

History
ID# Issue Date Notes

14083

16/07/2021 First DESK release

17005

03/03/2022 DESK 3.0.0 release

170xx

04/10/2022 Adding libgpiod example


Peripheral GPIOs[edit | edit source]

i.MX6 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 an example of device tree configuration for using the RS-485 GPIOs used on standard DAVE's kit for the AXEL Lite SOM:

From imx6q-sbcx-cb0012.dts:

    leds {
        compatible = "gpio-leds";
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_rs232_485_422_1>;

        rs232_485_422 {
            gpios = <&gpio7 13 GPIO_ACTIVE_HIGH>;
            linux,default-trigger = "default-on";
        };

        rs232_on {
            gpios = <&gpio5 29 GPIO_ACTIVE_LOW>;
            linux,default-trigger = "default-on";
        };
    };
};

From mx6qdl-sbcx-revb-common.dtsi:

    rs232_485_422 {
        pinctrl_rs232_485_422_1: pinctrl_rs232_485_422_grp-1 {
            fsl,pins = <
                MX6QDL_PAD_GPIO_18__GPIO7_IO13      0x1b0b1 /* UART5_485/232 */
                MX6QDL_PAD_CSI0_DAT11__GPIO5_IO29   0x1b0b1 /* UART5_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-mx6:~# ls -la /sys/class/leds/
total 0
drwxr-xr-x  2 root root 0 Apr  2  2020 .
drwxr-xr-x 54 root root 0 Apr  2  2020 ..
lrwxrwxrwx  1 root root 0 Apr  2  2020 mmc0:: -> ../../devices/soc0/soc/2100000.aips-bus/2190000.usdhc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Apr  2  2020 mmc1:: -> ../../devices/soc0/soc/2100000.aips-bus/2194000.usdhc/leds/mmc1::
lrwxrwxrwx  1 root root 0 Apr  2  2020 rs232_485_422 -> ../../devices/soc0/leds/leds/rs232_485_422
lrwxrwxrwx  1 root root 0 Apr  2  2020 rs232_on -> ../../devices/soc0/leds/leds/rs232_on
root@desk-mx6:~#

Usage with sysfs[edit | edit source]

  • set EIM_D26 (MX6QDL_PAD_EIM_D26__GPIO3_IO26) as output GPIO
    • GPIO3_IO26 => (n-1)*32 + IO = (3-1)*32+26 = 90
root@desk-mx6:~# echo 90 > /sys/class/gpio/export
root@desk-mx6:~# echo out > /sys/class/gpio/gpio90/direction
root@desk-mx6:~# echo 1 > /sys/class/gpio/gpio90/value
root@desk-mx6:~#
  • set EIM_D27 (MX6QDL_PAD_EIM_D27__GPIO3_IO27) as input GPIO
root@desk-mx6:~# echo 91 > /sys/class/gpio/export
root@desk-mx6:~# echo in > /sys/class/gpio/gpio91/direction
root@desk-mx6:~# cat /sys/class/gpio/gpio91/value
1
root@desk-mx6:~#
Additional information[edit | edit source]

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

Usage with libgpiod[edit | edit source]

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

libgpiod usage[edit | edit source]

It is possible yo cross-compile libgpiod in the target (if the related Yocto package is not available for installation). Once the autoconf-archive package has been installed

dnf install autoconf-archive

it is possible to clone the libgpiod git repository and compile the related sources:

git clone https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
cd libgpiod 
./autogen.sh --enable-tools=yes --prefix=/usr/local 
make
make install

Once installed, the <code>gpio</code> utilities are availabel in the target:

<pre class="workstation-terminal">
root@desk-mx6:~# gpio
gpiodetect  gpiofind    gpioget     gpioinfo    gpiomon     gpioset
root@desk-mx6:~# gpio
gpio interrupt example[edit | edit source]

If a push button, with proper pull-up, is connected to a GPIO line available - for example using the J33.34 pin available on WIDE connector - the related GPIO can be used as an interrupt:

  • J33.40 is connected to J10.40 SOM pin (is J10 connector on SBC AXEL Lite EVK)
    • ALT-5 alternate function for this pin is GPIO1_IO06
  • the corresponding pin number is 0 6
  • gpiomon utility can be used for monitor the pin status and triggering, for exmaple, the 'falling-edge event
root@desk-mx6:~# gpiomon --falling-edge 0 6
event: FALLING EDGE offset: 6 timestamp: [     696.463539802]
event: FALLING EDGE offset: 6 timestamp: [     696.643661944]
^Croot@desk-mx6:~#