TS-4100 DIO

From embeddedTS Manuals
Revision as of 17:22, 13 June 2019 by Kris (talk | contribs) (Clean up.)

The i.MX6UL and FPGA GPIO are exposed using the kernel's sysfs GPIO interface. See the kernel's documentation here for more detail. This interface provides a set of files and directories for interacting with GPIO which can be used from any language that can write files.

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

echo "71" > /sys/class/gpio/export
# GPIO 71 is CPU LCD_D02

If the command returns with "permission denied," that means that specific GPIO is claimed by another device. The command 'cat /sys/kernel/debug/gpio' can be used to get a list of all of the system GPIO and what has claimed them.

If the command was successful, the directory "/sys/class/gpio/gpio71/" will have been created. The relevant files in this directory are:

 direction - write "in", "out" (out = low), "low", "high"
 value - write "1" or "0", or read "1" or "0" if direction is in
 edge - write "rising", "falling", or "none"

With "direction", the GPIO can be set to an output and direction set at the same time using the "high" and "low" commands. Using "out" will act the same as "low".

# Set as a low output
echo "out" > /sys/class/gpio/gpio71/direction
# Set GPIO 71 high
echo "1" > /sys/class/gpio/gpio71/value
# Set GPIO 71 low
echo "0" > /sys/class/gpio/gpio71/value

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

# Set as a high output
echo "high" > /sys/class/gpio/gpio71/direction

As an output, the "value" file can be written with "0" for low output (GND), or "1" for high output (3.3V). The GPIO pins support an absolute maximum of -0.5 to 3.6 V input; any voltage outside of this range can damage the pin or the device. It is also possible to use any processor GPIO as an interrupt by writing the "edge" file with a value, and then using select() or poll() on the "value" file for changes. The kernel documentation provides information on this and other use cases of the sysfs GPIO interface.