How to use GPIO on TechNexion modules

Difficulty Levels: Intermediate
Date added: July 21, 2020
Affected Products: AXON SoM's , EDM Modules , EDM1-CF-IMX6 , FLEX System on Modules , PICO Compute Modules , TC-0700 / TC-0710 , TC-1010 , TEK3-IMX6 , TEK3-IMX6UL , TEP-0500-IMX6UL , TEP-0500-IMX7 , TEP-0700-IMX6UL , TEP-0700-IMX7 , TEP-1010-IMX6 , TEP-1560-IMX6 , TEP-2150FHD-IMX6 , TWP-1010-IMX6 , TWP-1560-IMX6 , XORE SoM's

The Linux kernel SysFS-based GPIO userspace feature has been deprecated and is being discontinued. Its continued use is discouraged in favor of a new userspace char device driver and API (libgpiod).

The new character device and API makes use of /dev/gpiochip devices through ioctl calls:

root@pico-imx8mm:~# ls /dev/gpiochip*
/dev/gpiochip0 /dev/gpiochip1 /dev/gpiochip2 /dev/gpiochip3 /dev/gpiochip4

Each entry in /dev/gpiochip corresponds to a GPIO device (i.e. a bank of GPIOs). In i.MX, each bank can contain up to 32 GPIO lines (0-31).

To get the GPIO correspond to a particular module pin, you might reference the hardware manual for the module. In some cases, you might also need to reference the SOC reference manual.

For example, in the PICO-IMX8M-MINI Hardware Reference Manual:

Using the Command Line Tools

To make GPIO simple to access via scripts and the command line, there are several command line tools available.

gpiodetect: Search for gpio devices and indicate how many GPIOs are controlled by each.

root@pico-imx8mm:~# gpiodetect
gpiochip0 [30200000.gpio] (32 lines)
gpiochip1 [30210000.gpio] (32 lines)
gpiochip2 [30220000.gpio] (32 lines)
gpiochip3 [30230000.gpio] (32 lines)
gpiochip4 [30240000.gpio] (32 lines)

gpioinfo: List the information for the gpio lines per bank.

root@pico-imx8mm:~# gpioinfo
gpiochip0 - 32 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed "interrupt" input active-high [used]
line 4: unnamed unused input active-high
line 5: unnamed unused output active-high
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: unnamed unused input active-high
line 9: unnamed "usb_otg_vbus" output active-high [used]
line 10: unnamed "backlight_pwr" output active-high [used]
line 11: unnamed "WL_REG_ON" output active-high [used]
line 12: unnamed "?" output active-high [used]

This command is useful to see which GPIOs are already used, are inputs/outputs, and their active state (high/low). Adding a number after the command, corresponding to the bank, will list only the GPIOs in that bank. No argument lists all the GPIOs in all banks.

gpioset: Set a the value of a GPIO. For example, setting the value of line 9 of gpio bank 3 to 1 below:

root@pico-imx8mm:~# gpioset gpiochip3 9=1
You can also omit the ‘gpiochip’ name below as:
root@pico-imx8mm:~# gpioset 3 9=1
Setting the value to 0:
root@pico-imx8mm:~# gpioset 3 9=0

gpioget: Get a the value of a GPIO. For example, read the value of line 8 of gpio bank 3:

root@pico-imx8mm:~# gpioget gpiochip3 8
0

You can also omit the ‘gpiochip’ name below as:
root@pico-imx8mm:~# gpioget 3 8
0

 

Stay up to date with all the latest TechNexion news...

Sign-up for our Newsletter