TS-4100 DIO: Difference between revisions

From embeddedTS Manuals
(Consistency of naming.)
(Clean up.)
Line 3: Line 3:
To interact with a pin, first export it to userspace:
To interact with a pin, first export it to userspace:
<source lang=bash>
<source lang=bash>
echo "48" > /sys/class/gpio/export
echo "71" > /sys/class/gpio/export
# GPIO 71 is CPU LCD_D02
</source>
</source>


If you receive a permission denied on a pin that means it is claimed by another kernel driver. In this case, you can "cat /sys/kernel/debug/gpio" to see what driver has claimed it. If it succeeds you will have a /sys/class/gpio/gpio48/ directory.  The relevant files in this directory are:
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.
   direction - "in", "out" (out = low), "low", "high"
 
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
   value - write "1" or "0", or read "1" or "0" if direction is in
   edge - write with "rising", "falling", or "none"
   edge - write "rising", "falling", or "none"


With direction you can set it as an output and set the direction at the same time with high/low. If you just specify out this is the same as low.
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".


<source lang=bash>
<source lang=bash>
# Set as a low output
# Set as a low output
echo "out" > /sys/class/gpio/gpio48/direction
echo "out" > /sys/class/gpio/gpio71/direction
# Set GPIO 48 high
# Set GPIO 71 high
echo "1" > /sys/class/gpio/gpio48/value
echo "1" > /sys/class/gpio/gpio71/value
# Set GPIO 48 low
# Set GPIO 71 low
echo "0" > /sys/class/gpio/gpio48/value
echo "0" > /sys/class/gpio/gpio71/value


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


# You can set it as a high output by setting the direction:
# Set as a high output
echo "high" > /sys/class/gpio/gpio48/direction
echo "high" > /sys/class/gpio/gpio71/direction
</source>
</source>


As an output, the in can be written to 0 for low (GND), or 1 for high (3.3V). The GPIO pins directly off of the i.MX6ul processor support an absolute maximum of -0.5 to 3.6V.  It is also possible to use any processor GPIO as an interrupt by writing the edge value, and then using select() or poll() on the value file for changes.
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 [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt kernel documentation] provides information on this and other use cases of the sysfs GPIO interface.

Revision as of 17:22, 13 June 2019

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.