Open main menu

DAVE Developer's Wiki β

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

< DESK-MX6-L
(Created page with "{{subst:Peripheral | nome-som=AXEL Lite | nome-peripheral = GPIOs }}")
 
m (U0007 moved page DESK-MX6-L/Pheripherals/GPIOs to DESK-MX6-L/Peripherals/GPIOs without leaving a redirect)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<section begin=History/>
+
<section begin="History" />
 
{| style="border-collapse:collapse; "
 
{| style="border-collapse:collapse; "
!colspan="4" style="width:100%; text-align:left"; border-bottom:solid 2px #ededed"|History
+
! colspan="4" style="width:100%; text-align:left" ; border-bottom:solid 2px #ededed" |History
 
|-  
 
|-  
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Version
+
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white" |Issue Date
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Issue Date
+
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white" |Notes
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
 
 
|-
 
|-
|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"|X.Y.Z
+
| 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|14083|2021/07/16}}
|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"|Month Year
+
| 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-MX6-L 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"|TBD
 
 
|-
 
|-
 +
| 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|2022/03/03}}
 +
| 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-MX6-L 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"|[TBD_link X.Y.Z]
+
| 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|17064|2022/10/04}}
|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"|Month Year
+
| 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" |Add libgpiod example
|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"|TBD
 
 
|-
 
|-
|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"|...
+
 
|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"|...
+
! 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" |2023/04/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"|...
+
! 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-MX6-L 4.0.0 release
 
|-
 
|-
 
|}
 
|}
<section end=History/>
+
<section end="History" />
<section begin=Body/>
+
<section begin="Body" />
  
 
==Peripheral GPIOs ==
 
==Peripheral GPIOs ==
  
''TBD: sostituire tutti i dump con le informazioni sull'uso della periferica''
+
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 ===
 
=== Device tree configuration ===
Here below an example of device tree configuration used on standard DAVE's kit for the AXEL Lite SOM:
+
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 <code>''carrier.dts''</code>:
+
From <code>imx6q-sbcx-cb0012.dts</code>:
  
 
<pre>
 
<pre>
&can1 {
+
    leds {
    pinctrl-names = "default";
+
        compatible = "gpio-leds";
    pinctrl-0 = <&pinctrl_flexcan1_axel>;
+
        pinctrl-names = "default";
    status = "okay";
+
        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";
 +
        };
 +
    };
 
};
 
};
 
</pre>
 
</pre>
  
From <code>''carrier-common.dtsi''</code>:
+
From <code>mx6qdl-sbcx-revb-common.dtsi</code>:
  
 
<pre>
 
<pre>
     can1 {
+
     rs232_485_422 {
         pinctrl_flexcan1_axel: flexcan1axelgrp-1 {
+
         pinctrl_rs232_485_422_1: pinctrl_rs232_485_422_grp-1 {
 
             fsl,pins = <
 
             fsl,pins = <
                 MX6QDL_PAD_GPIO_7__FLEXCAN1_TX 0x80000000
+
                 MX6QDL_PAD_GPIO_18__GPIO7_IO13      0x1b0b1 /* UART5_485/232 */
                 MX6QDL_PAD_GPIO_8__FLEXCAN1_RX 0x80000000
+
                 MX6QDL_PAD_CSI0_DAT11__GPIO5_IO29  0x1b0b1 /* UART5_ON */
 
             >;
 
             >;
 
         };
 
         };
Line 56: Line 67:
 
===Accessing the peripheral===
 
===Accessing the peripheral===
 
====Linux messages at boot time====
 
====Linux messages at boot time====
 +
 +
With the previous <code>leds</code> configuration for the GPIOs, it is possible to find them on <code>sysfs</code> under ''/sys/class/leds'' sub-directory:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
...
+
root@desk-mx6:~# ls -la /sys/class/leds/
...
+
total 0
[    1.807495] flexcan 2090000.flexcan: 2090000.flexcan supply xceiver not found, using dummy regulator
+
drwxr-xr-x  2 root root 0 Apr 28  2022 .
[    1.817366] flexcan 2090000.flexcan: device registered (reg_base=c0a30000, irq=31)
+
drwxr-xr-x 58 root root 0 Apr 28  2022 ..
...
+
lrwxrwxrwx  1 root root 0 Apr 28  2022 mmc0:: -> ../../devices/platform/soc/2100000.bus/2190000.mmc/leds/mmc0::
...
+
lrwxrwxrwx  1 root root 0 Apr 28  2022 mmc1:: -> ../../devices/platform/soc/2100000.bus/2194000.mmc/leds/mmc1::
[    3.952659] can: controller area network core (rev 20170425 abi 9)
+
lrwxrwxrwx  1 root root 0 Apr 28  2022 rs232_485_422 -> ../../devices/platform/leds/leds/rs232_485_422
[    3.963413] can: raw protocol (rev 20170425)
+
lrwxrwxrwx  1 root root 0 Apr 28  2022 rs232_on -> ../../devices/platform/leds/leds/rs232_on
[    3.967717] can: broadcast manager protocol (rev 20170425 t)
 
[    3.973397] can: netlink gateway (rev 20170425) max_hops=1
 
 
</pre>
 
</pre>
  
====Enable the interface and check status====
+
===Userspace gpio access ===
 +
==== Usage with [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt sysfs] ====
 +
 
 +
* set EIM_D26 (MX6QDL_PAD_EIM_D26__GPIO3_IO26) as output GPIO
 +
** GPIO3_IO26 => (n-1)*32 + IO = (3-1)*32+26 = 90
 +
 
 +
<pre class="workstation-terminal">
 +
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:~#
 +
</pre>
 +
 
 +
* set EIM_D27 (MX6QDL_PAD_EIM_D27__GPIO3_IO27) as input GPIO
 +
 
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@imx6qxelk:~# ip link set can0 type can bitrate 500000
+
root@desk-mx6:~# echo 91 > /sys/class/gpio/export
root@imx6qxelk:~# ifconfig can0 up
+
root@desk-mx6:~# echo in > /sys/class/gpio/gpio91/direction
root@imx6qxelk:~# ifconfig can0
+
root@desk-mx6:~# cat /sys/class/gpio/gpio91/value
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
+
1
          UP RUNNING NOARP  MTU:16  Metric:1
+
root@desk-mx6:~#
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
+
</pre>
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
+
 
          collisions:0 txqueuelen:10
+
===== Additional information =====
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
+
Information about GPIOs usage under <code>sysfs</code> directory ''https://www.kernel.org/doc/Documentation/gpio/sysfs.txt''
          Interrupt:31
+
 
 +
==== Usage with [https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README libgpiod] ====
  
root@imx6qxelk:~#
+
{{WarningMessage|text=''sysfs'' GPIO ABI has been deprecated. See more information [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]
 +
 
 +
===== libgpiod example =====
 +
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>
 
</pre>
  
==== Usage with [https://github.com/linux-can/can-utils can-utils] ====
+
it is possible to clone the <code>libgpiod</code> git repository and compile the related sources:
  
''TBD: reference verso eventuali informazioni sul web''
+
<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
 +
</pre>
 +
 
 +
Once installed, the <code>gpio</code> utilities are availabel in the target:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@imx6qxelk:~# ip link set can0 type can bitrate 500000 triple-sampling on
+
root@desk-mx6:~# gpio
root@imx6qxelk:~# ifconfig can0 up
+
gpiodetect gpiofind    gpioget    gpioinfo    gpiomon    gpioset
root@imx6qxelk:~# cansend can0 128#1122334455667788
 
root@imx6qxelk:~# candump can0
 
  can0 128  [8]  11 22 33 44 55 66 77 88
 
root@imx6qxelk:~#
 
 
</pre>
 
</pre>
  
=== Additional information ===
+
===== gpio interrupt example =====
Each CAN port appears like a networking interface in the form <code>canX</code> where <b><i>X</i></b> is the port number.
+
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 | SBC AXEL Lite WIDE]] connector - the related GPIO can be used as an interrupt:
 +
 
 +
* J33.40 is connected to J10.40 SOM pin
 +
** J33 connector is the WIDE connector in the [[AXEL_Lite_SOM/AXEL_Lite_Evaluation_Kit | AXEL Lite EVK]]
 +
** J10 connector is the SO-DIMM connector in the AXEL Lite EVK
 +
** ALT-5 alternate function for this pin is <code>GPIO1_IO06</code>
 +
* the corresponding pin number is 0 6
 +
* <code>gpiomon</code> utility can be used for monitor the pin status and triggering, for example, 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>
  
Information about programming the CAN socket interface is given in the kernel tree under ''Documentation/networking/can.txt''
+
<section end="Body" />
<section end=Body/>
 
  
 
----
 
----
  
 
[[Category:AXEL Lite]]
 
[[Category:AXEL Lite]]

Latest revision as of 10:44, 13 May 2024

History
Issue Date Notes

2021/07/16

First DESK-MX6-L release

2022/03/03

DESK-MX6-L 3.0.0 release

2022/10/04

Add libgpiod example
2023/04/11 DESK-MX6-L 4.0.0 release


Contents

Peripheral GPIOsEdit

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 configurationEdit

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 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-mx6:~# ls -la /sys/class/leds/
total 0
drwxr-xr-x  2 root root 0 Apr 28  2022 .
drwxr-xr-x 58 root root 0 Apr 28  2022 ..
lrwxrwxrwx  1 root root 0 Apr 28  2022 mmc0:: -> ../../devices/platform/soc/2100000.bus/2190000.mmc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Apr 28  2022 mmc1:: -> ../../devices/platform/soc/2100000.bus/2194000.mmc/leds/mmc1::
lrwxrwxrwx  1 root root 0 Apr 28  2022 rs232_485_422 -> ../../devices/platform/leds/leds/rs232_485_422
lrwxrwxrwx  1 root root 0 Apr 28  2022 rs232_on -> ../../devices/platform/leds/leds/rs232_on

Userspace gpio accessEdit

Usage with sysfsEdit

  • 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 informationEdit

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

Usage with libgpiodEdit

  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

libgpiod exampleEdit

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 gpio utilities are availabel in the target:

root@desk-mx6:~# gpio
gpiodetect  gpiofind    gpioget     gpioinfo    gpiomon     gpioset
gpio interrupt exampleEdit

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

  • J33.40 is connected to J10.40 SOM pin
    • J33 connector is the WIDE connector in the AXEL Lite EVK
    • J10 connector is the SO-DIMM connector in the 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 example, 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:~#