How to use GPIO for Diagnostic

Jump to: navigation, search

Please note that Pin configuration/muxing is a non-trivial part of the overall system design. It is easily possible to do illegal configurations when it comes to multiplexed pins (e.g. one pin driving low and the other one driving high). Even more though on SoCs where certain settings in this respect cannot be done per pin but rather only per pin group.


The i.MX bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_IO<gpio_bit>" 

The numeric value of GPIO is calculated as follows:

32 x (gpio_bank- 1) + gpio_bit

E.g. GPIO2_IO04 becomes 36

The Rockchip bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_[A-D]<gpio_bit>" 

The numeric value of GPIO is calculated as follows:

32 x gpio_bank + gpio_bit

E.g. GPIO2_A3 becomes 67,Note:GIPO0 only 24 pins in this group


To export a particular pin as GPIO for user control proceed as follows:

$ echo 189 > /sys/class/gpio/export

To change that GPIO pins direction to in/out:

$ echo "in" > /sys/class/gpio/gpio189/direction


$ echo "out" > /sys/class/gpio/gpio189/direction

To check the value (in case its direction is input):

Warning: On i.MX based modules one cannot read back the value which has been set to an output unless one did set the SION bit in the pin muxing.

$ cat /sys/class/gpio/gpio189/value

To change its value (in case its direction is output):

$ echo 1 > /sys/class/gpio/gpio189/value


$ echo 0 > /sys/class/gpio/gpio189/value

To directly force a GPIO to output and set its initial value (e.g. glitch free operation):

$ echo high > /sys/class/gpio/gpio189/direction


$ echo low > /sys/class/gpio/gpio189/direction

To configure a GPIO as an interrupt source:

Note: If a GPIO is configured as an input, one can configure the GPIO as an interrupt source. Configure GPIO if the interrupt occurs when the GPIO signal has a rising edge, a falling edge, or interrupts on both rising and falling edges.

$ echo "rising" > /sys/class/gpio/gpio189/edge

Possible values

  • rising: Trigger on rising edge
  • falling: Trigger on falling edge
  • both: Trigger on both edges
  • none: Disable interrupts on both edges

To un-export aka revert the exporting of a GPIO pin:

$ echo 189 > /sys/class/gpio/unexport

Warning: GPIOs which are already used in the drivers can not be controlled from sysfs, unless a driver explicitly exported that particular pins GPIO.

More information concerning the Linux' GPIO subsystem can be found in the following kernel documentation file: