...
This application note shows how to control the i.MX RT1050/RT1060 GPIOs from the user level using the standard Linux GPIOLIB
interface.
1. Changes to the Kernel Configuration
The generic GPIO interface is controlled by the CONFIG_GPIOLIB
kernel option enabled by default in the rootfs
project. Most of the i.MX RT1050/RT1060 GPIO pins can be used in different multiplexed I/O roles (for instance, some GPIO pins can be also configured as an SPI interface, etc.) Depending on the requirements of your application, you need to configure the pins that you want to use as GPIO for the GPIO role and other pins for an alternative I/O function.
...
After applying the above changes to the DTS file, rebuild the rootfs
project ( Building Linux ) and install it on the target (Building and Installing Linux uImage on the NXP i.MX RT10XX EVK Board ).
2. Testing GPIO
Each GPIO is assigned a unique integer GPIO number within the GPIO chip range of 0 to 142 by Linux. The i.MX RT1050/1060 supports 5 GPIO blocks (gpio_chips) of 32 pieces GPIO1, GPIO2, GPIO3, GPIO4 and GPIO5. Note that for the GPIO5 chip only 3 first signals are actually available: GPIO5_IO00, GPIO5_IO01 and GPIO5_IO02 - the rest are not output anywhere.
...
gpio number for
GPIO01.IO09
will be (1 – 1) * 32 + 512 + 9 = 521.gpio number for
GPIO05.IO00
will be (5 – 1) * 32 + 512 + 0 = 640.
2.1. Testing USER LED
Export
GPIO1_IO09
:Code Block / # echo 521 > /sys/class/gpio/export
Use the following command to turn on the
USER LED
:Code Block / # echo 0 > /sys/class/gpio/gpio521/value
Use the following command to turn off the
USER LED
:Code Block / # echo 1 > /sys/class/gpio/gpio521/value
2.2. Testing USER BUTTON
Export
GPIO5_IO00
:Code Block / # echo 640 > /sys/class/gpio/export
Make sure the value of
GPIO5_IO00
is 1 when theUSER BUTTON
is untouched (due to the internal PULL-UP being enabled):Code Block / # cat /sys/class/gpio/gpio640/value1
Press and hold the
USER BUTTON
and make sure theGPIO5_IO00
value has changed to 0:Code Block / # cat /sys/class/gpio/gpio640/value 0
3. Alternative Ways to Access GPIO
In Linux, you may access GPIOs using different approaches, not only the ones described in this application note above. Here are some external links that might be useful if you decide to try an alternative approach.
...