TS-4100 DIO: Difference between revisions

From embeddedTS Manuals
(Clean up.)
(Formatting changes)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The i.MX6UL and FPGA GPIO are exposed using the kernel's sysfs GPIO interface. See the kernel's documentation [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt 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.
The i.MX6UL CPU and FPGA GPIO are exposed using a kernel character device. This interface provides a set of files and directories for interacting with GPIO which can be used from any language that interact with special files in linux using ioctl() or similar. For our platforms, we pre-install the "libgpiod" library and binaries. Documentation on these tools can be found [https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README here]. This section only covers using these userspace tools and does not provide guidance on using the libgpiod library in end applications. Please see the libgpiod documentation for this purpose.


To interact with a pin, first export it to userspace:
A user with suitable permissions to read and write <source inline>/dev/gpiochip*</source> files can immediately interact with GPIO pins. For example, to read the push switch on the TS-8551-4100 which is connected to [[#FPGA_GPIO_Table|FPGA DIO_9]]:
<source lang=bash>
<source lang=bash>
echo "71" > /sys/class/gpio/export
gpioget 5 46
# GPIO 71 is CPU LCD_D02
</source>
</source>
Multiple pins in the same chip can be read simultaneously by passing multiple pin numbers separated by spaces.


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.
To write to a pin, the <source inline>gpioset</source> command is used. For example, to set [[#CPU_GPIO_Table|LCD_D02]]:
 
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".
 
<source lang=bash>
<source lang=bash>
# Set as a low output
gpioset 2 7=0
echo "out" > /sys/class/gpio/gpio71/direction
</source>
# Set GPIO 71 high
Multiple pins in the same chip can be set simultaneously by passing multiple <source inline><pin>=<value></source> pairs separated by spaces.
echo "1" > /sys/class/gpio/gpio71/value
# Set GPIO 71 low
echo "0" > /sys/class/gpio/gpio71/value


# Read the value of GPIO 71
If a call to <source inline>gpioset</source> or <source inline>gpioget</source> fails with the message <source inline>Device or resource busy</source> that means that specific GPIO is claimed by another device. The command <source inline>cat /sys/kernel/debug/gpio</source> can be used to get a list of all of the system GPIO and what has claimed them.
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
</source>


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.
The <source inline>gpiomon</source> tool can be used to monitor pins for changes.

Latest revision as of 16:09, 19 October 2021

The i.MX6UL CPU and FPGA GPIO are exposed using a kernel character device. This interface provides a set of files and directories for interacting with GPIO which can be used from any language that interact with special files in linux using ioctl() or similar. For our platforms, we pre-install the "libgpiod" library and binaries. Documentation on these tools can be found here. This section only covers using these userspace tools and does not provide guidance on using the libgpiod library in end applications. Please see the libgpiod documentation for this purpose.

A user with suitable permissions to read and write /dev/gpiochip* files can immediately interact with GPIO pins. For example, to read the push switch on the TS-8551-4100 which is connected to FPGA DIO_9:

gpioget 5 46

Multiple pins in the same chip can be read simultaneously by passing multiple pin numbers separated by spaces.

To write to a pin, the gpioset command is used. For example, to set LCD_D02:

gpioset 2 7=0

Multiple pins in the same chip can be set simultaneously by passing multiple <pin>=<value> pairs separated by spaces.

If a call to gpioset or gpioget fails with the message Device or resource busy 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.

The gpiomon tool can be used to monitor pins for changes.