TS-4900 DIO

From embeddedTS Manuals

For kernels 4.9 and below

The i.MX6 GPIO are available using the kernel sysfs interface. See the kernel's documentation here for more detail. This interface provides a set of files and directories for interacting with GPIO. This allows GPIO to be accessed from any language that can read and write files.

To interact with this pin, first export it to userspace:

echo "48" > /sys/class/gpio/export

If the command returns with a permission denied on a GPIO that means it is claimed by another kernel driver. If it succeeds, the kernel will create the /sys/class/gpio/gpio48/ directory. The relevant files in this directory are:

 direction - "in", "high", "low", or "out".  Out is equivalent to low
 value - write "1" or "0", or read "1" or "0" if direction is in
 edge - write with "rising", "falling", or "none"
# Set GPIO 48 high
echo "out" > /sys/class/gpio/gpio48/direction
echo "1" > /sys/class/gpio/gpio48/value
# Set GPIO 48 low
echo "0" > /sys/class/gpio/gpio48/value

# Read the value of GPIO 48
echo "in" > /sys/class/gpio/gpio48/direction
cat /sys/class/gpio/gpio48/value

As an output, the value file can be written with 0 for low (GND), or 1 for high (3.3 V). As an input the GPIO will have a 100 kohm pullup. The GPIO pins from the i.MX6 processor support an absolute maximum voltage range of -0.5 V to 3.6 V. It is also possible to use any processor GPIO as an interrupt. This is done by writing the edge file and using select() or poll() on the value file to watch for changes. See the Interrupts section for more details.


For kernels 5.10 and newer

GPIO pins can be interacted with via gpiod tools such as gpioset and gpioget. For example, HD1_DIO_1 is chip and line 7 19:

gpioset 7 19=1  # Set the pin high
gpioset 7 19=0  # Set the pin low


Note that the gpiod tools syntax has changed over time. Version 2.2.x of gpiod and newer use line names. The example above would look like:

gpioset -t0 HD1_DIO_1=1  # Set the pin high
gpioset -t0 HD1_DIO_1=0  # Set the pin low


To read the value of a GPIO line, gpioget can be used, for example to read the state of the HD1_DIO_1 on chip and line 7 19:

gpioget 7 19


As above, version 2.2.x of gpiod uses line names and has slightly different syntax:

gpioget "HD1_DIO_1"


In all cases, every GPIO line in a system, its chip, line, and line name, can all be listed at once with the gpioinfo command.