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

From DAVE Developer's Wiki
Jump to: navigation, search
m (U0007 moved page DESK-MX8M-L/Pheripherals/GPIOs to DESK-MX8M-L/Peripherals/GPIOs without leaving a redirect)
 
(9 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
!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"|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"|{{oldid|15751|2022/01/14}}
|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-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"|First DESK-MX8M 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" |{{oldid|17610|2023/02/24}}
 +
| 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-MX8M-L-2.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" |2023/08/22
 +
! 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-MX8M-L-4.0.0 release
 +
|-
 
|}
 
|}
 
<section end=History/>
 
<section end=History/>
Line 21: Line 25:
  
 
=== Device tree configuration ===
 
=== Device tree configuration ===
 +
 +
==== ORCA SOM ====
 +
 
Here below a simple example of device tree configuration for using a GPIO on DAVE's kit for the ORCA SOM with [https://www.kernel.org/doc/Documentation/leds/leds-class.txt gpio-leds] sysfs interface:
 
Here below a simple example of device tree configuration for using a GPIO on DAVE's kit for the ORCA SOM with [https://www.kernel.org/doc/Documentation/leds/leds-class.txt gpio-leds] sysfs interface:
  
Line 26: Line 33:
  
 
<pre>
 
<pre>
      leds {
+
leds {
      compatible = "gpio-leds";
+
compatible = "gpio-leds";
  
      gpio-test {
+
ptn36043_gpio {
              gpios = <&gpio4 24 GPIO_ACTIVE_HIGH>;
+
/* this gpio set the USB-C crossbar switch direction.
              default-state = "off";
+
* As the connected peripheral would always be the power source of
          };
+
* the system, hotplug is not possible.
      };
+
* It's status is configured by the bootloader according to the CC
 +
* direction and has only to be preserved during the execution.
 +
* see usb_dwc3_0 for more details */
 +
gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>;
 +
default-state = "keep";
 +
};
 +
};
 
...
 
...
 
...
 
...
 
&iomuxc {
 
&iomuxc {
      pinctrl-names = "default";
+
...
      pinctrl-0 = <&pinctrl_hog>;
+
...
 
+
pinctrl_gpio_led: gpioledgrp {
      pinctrl_hog: hoggrp {
+
fsl,pins = <
        fsl,pins = <
+
MX8MP_IOMUXC_NAND_READY_B__GPIO3_IO16 0x19
                      MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24 0x19
+
>;
        >;
+
};
    };
+
...
 +
...
 
};
 
};
 
</pre>
 
</pre>
  
===Accessing the peripheral===
+
===Accessing the peripheral in ORCA SOM===
 
====Linux messages at boot time====
 
====Linux messages at boot time====
  
Line 56: Line 70:
 
root@desk-mx8mp:~# ls -la /sys/class/leds/
 
root@desk-mx8mp:~# ls -la /sys/class/leds/
 
total 0
 
total 0
drwxr-xr-x  2 root root 0 Jan 14 12:08 .
+
drwxr-xr-x  2 root root 0 Jul 26 05:52 .
drwxr-xr-x 82 root root 0 Jan 14 12:08 ..
+
drwxr-xr-x 87 root root 0 Jul 26 05:52 ..
lrwxrwxrwx  1 root root 0 Jan 14 12:08 gpio-test -> ../../devices/platform/leds/leds/gpio-test
+
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc0:: -> ../../devices/platform/soc@0/30800000.bus/30b40000.mmc/leds/mmc0::
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 Jul 26 05:52 mmc1:: -> ../../devices/platform/soc@0/30800000.bus/30b50000.mmc/leds/mmc1::
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 Jul 26 05:52 mmc2:: -> ../../devices/platform/soc@0/30800000.bus/30b60000.mmc/leds/mmc2::
lrwxrwxrwx  1 root root 0 Jan 14 12:08 mmc2:: -> ../../devices/platform/soc@0/30800000.bus/30b60000.mmc/leds/mmc2::
+
lrwxrwxrwx  1 root root 0 Jul 26 05:52 ptn36043_gpio -> ../../devices/platform/leds/leds/ptn36043_gpio
 
root@desk-mx8mp:~#
 
root@desk-mx8mp:~#
 
</pre>
 
</pre>
Line 69: Line 83:
 
* read actual led/GPIO status
 
* read actual led/GPIO status
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@desk-mx8mp:~# cat /sys/class/leds/gpio-test/brightness
+
root@desk-mx8mp:~# cat /sys/class/leds/ptn36043_gpio/brightness  
0
+
1
 
root@desk-mx8mp:~#
 
root@desk-mx8mp:~#
 +
</pre>
 +
* change led/GPIO status to Low (0)
 +
<pre class="workstation-terminal">
 +
root@desk-mx8mp:~# echo 0 > /sys/class/leds/ptn36043_gpio/brightness                                                                                                                                                                         
 +
root@desk-mx8mp:~# [ 7970.890896] usb 2-1: USB disconnect, device number 2
 
</pre>
 
</pre>
 
* change led/GPIO status to High (1)
 
* change led/GPIO status to High (1)
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@desk-mx8mp:~# echo 1 > /sys/class/leds/gpio-test/brightness
+
root@desk-mx8mp:~# echo 1 > /sys/class/leds/ptn36043_gpio/brightness                                                                                                                                                                        
 +
root@desk-mx8mp:~# [ 7978.902356] usb 2-1: new SuperSpeed USB device number 5 using xhci-hcd
 +
[ 7979.060143] hub 2-1:1.0: USB hub found
 +
[ 7979.064524] hub 2-1:1.0: 4 ports detected
 +
root@desk-mx8mp:~#
 
</pre>
 
</pre>
  
Line 98: Line 121:
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
 
root@desk-mx8mp:~# echo 1 > /sys/class/gpio/gpio119/value
 
root@desk-mx8mp:~# echo 1 > /sys/class/gpio/gpio119/value
 +
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value                                                                                                                                                                                         
 +
1
 +
root@desk-mx8mp:~# echo 0 > /sys/class/gpio/gpio119/value                                                                                                                                                                                   
 +
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value
 +
0
 +
root@desk-mx8mp:~#
 
</pre>
 
</pre>
  
Line 108: Line 137:
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
 
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value
 
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value
1
+
0
 
root@desk-mx8mp:~#
 
root@desk-mx8mp:~#
 
</pre>
 
</pre>
Line 126: Line 155:
 
----
 
----
  
[[Category:AXEL Lite]]
+
[[Category:ORCA]]

Latest revision as of 10:23, 8 January 2024

History
Issue Date Notes

2022/01/14

First DESK-MX8M-L release

2023/02/24

DESK-MX8M-L-2.0.0 release
2023/08/22 DESK-MX8M-L-4.0.0 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]

ORCA SOM[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";

		ptn36043_gpio {
			/* this gpio set the USB-C crossbar switch direction.
			 * As the connected peripheral would always be the power source of
			 * the system, hotplug is not possible.
			 * It's status is configured by the bootloader according to the CC
			 * direction and has only to be preserved during the execution.
			 * see usb_dwc3_0 for more details */
			gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>;
			default-state = "keep";
		};
	};
...
...
&iomuxc {
...
...
	pinctrl_gpio_led: gpioledgrp {
		fsl,pins = <
			MX8MP_IOMUXC_NAND_READY_B__GPIO3_IO16	0x19
		>;
	};
...
...
};

Accessing the peripheral in ORCA SOM[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 Jul 26 05:52 .
drwxr-xr-x 87 root root 0 Jul 26 05:52 ..
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc0:: -> ../../devices/platform/soc@0/30800000.bus/30b40000.mmc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc1:: -> ../../devices/platform/soc@0/30800000.bus/30b50000.mmc/leds/mmc1::
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc2:: -> ../../devices/platform/soc@0/30800000.bus/30b60000.mmc/leds/mmc2::
lrwxrwxrwx  1 root root 0 Jul 26 05:52 ptn36043_gpio -> ../../devices/platform/leds/leds/ptn36043_gpio
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/ptn36043_gpio/brightness 
1
root@desk-mx8mp:~#
  • change led/GPIO status to Low (0)
root@desk-mx8mp:~# echo 0 > /sys/class/leds/ptn36043_gpio/brightness                                                                                                                                                                          
root@desk-mx8mp:~# [ 7970.890896] usb 2-1: USB disconnect, device number 2
  • change led/GPIO status to High (1)
root@desk-mx8mp:~# echo 1 > /sys/class/leds/ptn36043_gpio/brightness                                                                                                                                                                          
root@desk-mx8mp:~# [ 7978.902356] usb 2-1: new SuperSpeed USB device number 5 using xhci-hcd
[ 7979.060143] hub 2-1:1.0: USB hub found
[ 7979.064524] hub 2-1:1.0: 4 ports detected
root@desk-mx8mp:~#

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
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value                                                                                                                                                                                          
1
root@desk-mx8mp:~# echo 0 > /sys/class/gpio/gpio119/value                                                                                                                                                                                     
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value 
0
root@desk-mx8mp:~#

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
0
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