PHYTEC
Page 30
GPIOs
The phyBOARD-Pollux has a set of pins especially dedicated as a user I/Os. Those pins are connected directly to i.MX 8M Plus pins and are muxed as
GPIOs. They are directly usable in
userspace. The processor has organized its GPIOs into five banks of 32 GPIOs each (GPIO1 – GPIO5) and one
Linux
bank with 32 GPIOs.
,
,
,
and
are the
representation of these internal i.MX 8M Plus GPIO
gpiochip0 gpiochip32 gpiochip64 gpiochip96,
gpiochip128
sysfs
banks GPIO1 – GPIO5.
In the schematic GPIOs are identified as GPIO<X>_<Y> (e.g. GPIO5_07). <X> identifies the GPIO bank and counts from 1 to 5, while <Y> stands for the
GPIO within the bank. <Y> is being counted from 0 to 31 (32 GPIOs on each bank).
By contrast, the
kernel uses a single integer to enumerate all available GPIOs in the system. The formula to calculate the right number is:
Linux
Linux GPIO number: <N> = (<X> - 1) * 32 + <Y>
Accessing GPIOs from userspace will be done using the
. It provides a library and tools for interacting with the Linux GPIO character device. The
libgpiod
used pins have to be configured as GPIO in kernel before usage. Examples of the usage for some of the tools:
Detecting the gpiochips on the chip:
target$ gpiodetect
gpiochip0 [30200000.gpio] (32 lines)
gpiochip1 [30210000.gpio] (32 lines)
gpiochip2 [30220000.gpio] (32 lines)
gpiochip3 [30230000.gpio] (32 lines)
gpiochip4 [30240000.gpio] (32 lines)
Show detailed information about the gpiochips. Like their names, consumers, direction, active state, and additional flags:
target$ gpioinfo gpiochip0
Read the value of a GPIO (e.g GPIO 20 from chip0):
target$ gpioget gpiochip0 20
Set value of GPIO 20 on chip0 to 0 and exit tool:
target$ gpioset --mode=exit gpiochip0 20=0
Help text of
shows possible options:
gpioset