Trucrux Inc

Testing GPIO

Login to device

To get the state of GPIO run the following command

root@imx8mm-trux-q01:~# cat /sys/kernel/debug/gpio

Output :

gpiochip0: GPIOs 0-31, parent: platform/30200000.gpio, 30200000.gpio:
gpio-3 ( |ads7846_pendown ) in hi IRQ 
gpio-7 ( |regulator-eth-phy ) out hi ACTIVE LOW
gpio-9 ( |phy-reset ) out hi 
gpio-10 ( |id ) in lo IRQ 
gpio-12 ( |spi_imx ) out hi

gpiochip1: GPIOs 32-63, parent: platform/30210000.gpio, 30210000.gpio:
gpio-38 ( |sysfs ) out hi 
gpio-42 ( |WL_REG_ON ) out hi 
gpio-44 ( |cd ) in lo IRQ ACTIVE LOW
gpio-51 ( |regulator-usdhc2 ) out hi

gpiochip2: GPIOs 64-95, parent: platform/30220000.gpio, 30220000.gpio:

gpiochip3: GPIOs 96-127, parent: platform/30230000.gpio, 30230000.gpio:
gpio-114 ( |eMMC ) out lo 
gpio-118 ( |spi_imx ) out hi

gpiochip4: GPIOs 128-159, parent: platform/30240000.gpio, 30240000.gpio:
gpio-133 ( |sysfs ) out lo 
gpio-137 ( |spi_imx ) out hi 
gpio-142 ( |scl ) out hi 
gpio-143 ( |sda ) in hi 
gpio-144 ( |scl ) out hi 
gpio-145 ( |sda ) in hi 
gpio-146 ( |scl ) out hi 
gpio-147 ( |sda ) in hi 
gpio-148 ( |scl ) out hi 
gpio-149 ( |sda ) in hi

Each GPIO is defined as “in” or “out” and the state is shown as “lo” or “hi”. This can be changed via ‘sys/class/gpio’

1. Export GPIO

root@imx8mm-trux-q01:~# echo <GPIO_NUMBER> > /sys/class/gpio/export

2. Configure GPIO

root@imx8mm-trux-q01:~# echo <in or out> > /sys/class/gpio<gpionumber>/direction

3. Changing the value of GPIO

root@imx8mm-trux-q01:~# echo <1 or 0> > /sys/class/gpio<gpionumber>/value

4. Read Gpio

  • direction
root@imx8mm-trux-q01:~# cat /sys/class/gpio<gpionumber>/direction
  • value
root@imx8mm-trux-q01:~# cat /sys/class/gpio<gpionumber>/value

5. Unexport gpio after use

root@imx8mm-trux-q01:~# echo <GPIO_NUMBER> > /sys/class/gpio/unexport