TS-4900 DIO: Difference between revisions

From embeddedTS Manuals
(Created page with "The i.MX6 GPIO are available using the kernel's sysfs. See the kernel's documentation [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt here] for more detail. This in...")
 
(Clarifications)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
The i.MX6 GPIO are available using the kernel's sysfs.  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. For example to toggle CN1_89/EIM_A22 the kernel maps this to GPIO 48See the table below for the full IO listing.
{{Note|It is possible to use memory mapped CPU registers as documented in the CPU reference manual to control GPIO.  When using this, be aware that the kernel may attempt to also access these registers for various reasons. Also note that each register represents a bank of GPIO pins. Use a read-modify-write operation to avoid disturbing other GPIO pins. We strongly recommend using the sysfs interface as described below.}}
 
The i.MX6 GPIO are available using the kernel sysfs 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.  This allows GPIO to be accessed from any language that can read and write files. For example, to toggle CN1_89/EIM_A22, the kernel maps this to GPIO 48 (See the table below for the full I/O mapping).


To interact with this pin, first export it to userspace:
To interact with this pin, first export it to userspace:
Line 6: Line 8:
</source>
</source>


If you receive a permission denied on a pin that means it is claimed by another kernel driver.  If it succeeds you will have a /sys/class/gpio/gpio48/ directory.  The relevant files in this directory are:
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 - "out" or "in"
   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
   value - write "1" or "0", or read "1" or "0" if direction is in
   edge - write with "rising", "falling", or "none"
   edge - write with "rising", "falling", or "none"
Line 23: Line 25:
</source>
</source>


As an output, the in can be written to 0 for low (GND), or 1 for high (3.3V).  As an input the GPIO will have a 100k pullup.  The GPIO pins directly off of the i.MX6 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 (GND), or "1" for high (3.3V).  As an input the GPIO will have a 100k pullup.  The GPIO pins from the i.MX6 processor support an absolute maximum voltage range of -0.5 to 3.6V.  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|Interrupts section]] for more details.
{{Note|For custom carrier board designs, the 100k pullup is added in the device tree when the pin is specified as a GPIO.}}

Latest revision as of 16:28, 5 March 2019

Note: It is possible to use memory mapped CPU registers as documented in the CPU reference manual to control GPIO. When using this, be aware that the kernel may attempt to also access these registers for various reasons. Also note that each register represents a bank of GPIO pins. Use a read-modify-write operation to avoid disturbing other GPIO pins. We strongly recommend using the sysfs interface as described 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. For example, to toggle CN1_89/EIM_A22, the kernel maps this to GPIO 48 (See the table below for the full I/O mapping).

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.3V). As an input the GPIO will have a 100k pullup. The GPIO pins from the i.MX6 processor support an absolute maximum voltage range of -0.5 to 3.6V. 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.