Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updating numbered headings

...

This application note shows how to control the i.MX RT1170 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 RT1170 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.

...

  1. Verify that the USER LED and USER BUTTON interfaces are functional via the standard gpio-leds and gpio-keys interfaces:

    1. Use the following command to turn on the USER LED1:

      Code Block
      # echo 1 > /sys/class/leds/user-led1/brightness
    2. Use the following command to turn off the USER LED1:

      Code Block
      # echo 0 > /sys/class/leds/user-led1/brightness
    3. Use the following command to turn on the USER LED2:

      Code Block
      # echo 1 > /sys/class/leds/user-led2/brightness
    4. Use the following command to turn off the USER LED2:

      Code Block
      # echo 0 > /sys/class/leds/user-led2/brightness
  2. From the Linux shell, start the evtest utility. Then press the USER BUTTON and make sure the evtest has reported the events correctly:

    Code Block
    / # evtest /dev/input/event0
    Event: time 927.000134, type EV_KEY, code KEY_A, value 1
    Event: time 927.000134, type EV_SYN, code SYN_REPORT, value 0
    Event: time 927.240114, type EV_KEY, code KEY_A, value 0
    Event: time 927.240114, type EV_SYN, code SYN_REPORT, value 0
    0
  3. In order to test raw GPIO functions, disable definition of the USER BUTTON in the kernel DTS file, then rebuild and reinstall the project:

    Code Block
    diff --git a/rootfs/rootfs.dts.IMXRT117X_NXPEVK b/rootfs/rootfs.dts.
    IMXRT117X_NXPEVK
    index ab152d38..6fee00b8 100644
    --- a/rootfs/rootfs.dts.IMXRT117X_NXPEVK
    +++ b/rootfs/rootfs.dts.IMXRT117X_NXPEVK
    @@ -235,11 +235,13 @@
                    compatible = "gpio-keys";
                    pinctrl-names = "default";
                    pinctrl-0 = <&pinctrl_keys>;
    +#if 0
                    user-button {
                            label = "user-button";
                            gpios = <&gpio13 0 GPIO_ACTIVE_LOW>;
                            linux,code = <KEY_A>;
                    };
    +#endif                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
     };   
  4. Each GPIO is assigned a unique integer GPIO number within the GPIO chip range of 0 to 416 by Linux. The i.MX RT1170 supports 13 GPIO blocks of 32 pieces. To calculate that number for a specific GPIO, use the following formula
    gpio_idX(GPIOX_IOY) = (X - 1) * 32 + Y
    where an X value is a GPIO number and Y is a GPIO pin number.
    For example: gpio number for GPIO13.0 will be (13 -- 1) * 32 + 0 = 384.

  5. Export GPIO5_00 and configure it as an input:

    Code Block
    / # echo 384 > /sys/class/gpio/export
    / # echo in > /sys/class/gpio/gpio384/direction
  6. Make sure the value of GPIO13_00 is 1 when the USER BUTTON is untouched (due to the internal PULL-UP being enabled):

    Code Block
    / # cat /sys/class/gpio/gpio384/value
    1
    / #
  7. Press and hold the USER BUTTON and make sure the GPIO13_00 value has changed to 0:

    Code Block
    / # cat /sys/class/gpio/gpio384/value
    0
    

2. 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.

...