Changes

Jump to: navigation, search

DESK-MX8M-L/Peripherals/GPIOs

5,488 bytes added, 12:35, 14 January 2022
Created page with "<section begin=History/> {| style="border-collapse:collapse; " !colspan="4" style="width:100%; text-align:left"; border-bottom:solid 2px #ededed"|History |- !style="border-le..."
<section begin=History/>
{| style="border-collapse:collapse; "
!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"|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"|1.0.0
|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"|Jan 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"|First DESK-MX8M release

|}
<section end=History/>
<section begin=Body/>

==Peripheral GPIOs ==

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 ===
Here below an example of device tree configuration for using a GPIO for test on DAVE's kit for the ORCA SOM:

From <code>imx8mp-mito8mplus-cb1001.dts</code>:

<pre>
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
>;
};
};
</pre>

===Accessing the peripheral===
====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">
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:~#
</pre>

==== Usage as ''led'' function ====
Setting the brightness node, it is possible to change the GPIO status:
* read actual led/GPIO status
<pre class="workstation-terminal">
root@desk-mx8mp:~# cat /sys/class/leds/gpio-test/brightness
0
root@desk-mx8mp:~#
</pre>
* change led/GPIO status to High (1)
<pre class="workstation-terminal">
root@desk-mx8mp:~# echo 1 > /sys/class/leds/gpio-test/brightness
</pre>

==== Usage with [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt sysfs] ====
It is possible to configure the GPIO pin directly at Linux userspace using [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt sysfs] even if it is discouraged: see [[DESK-MX8M-L/Pheripherals/GPIO sysfs deprecated | 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
<pre class="workstation-terminal">
root@desk-mx8mp:~# echo 119 > /sys/class/gpio/export
</pre>
* configure the GPIO as output
<pre class="workstation-terminal">
root@desk-mx8mp:~# echo out > /sys/class/gpio/gpio119/direction
</pre>
* set the GPIO level
<pre class="workstation-terminal">
root@desk-mx8mp:~# echo 1 > /sys/class/gpio/gpio119/value
</pre>

For using the GPIO as input:

<pre class="workstation-terminal">
root@desk-mx8mp:~# echo in > /sys/class/gpio/gpio119/direction
</pre>
* read the GPIO level
<pre class="workstation-terminal">
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value
1
root@desk-mx8mp:~#
</pre>

'''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 ===
Information about GPIOs usage under ''sysfs'' directory ''https://www.kernel.org/doc/Documentation/gpio/sysfs.txt''

==== GPIO sysfs deprecated ====
{{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]

<section end=Body/>

----

[[Category:AXEL Lite]]
8,286
edits

Navigation menu