GPIO Utility on I-Pi SMARC 1200 Based on Yocto

This document provides detailed instructions for utilizing the gpio pins on the I-Pi SMARC 1200 module based on Yocto.

Prerequisites

  • GPIO libraries are included with our image by default.
  • Power up the targeted device with all the necessary cables, such as HDMI, keyboard, mouse, and ethernet cable.

Utilizing the GPIO Pins with Linux

  • Open the terminal and type the following command to navigate to gpio,

    cd /sys/class/gpio
  • To find the gpiochip details

     gpiodetect

    root@lec-mtk-i1200-ufs:~# gpiodetect
    gpiochip0 [pinctrl_paris] (165 lines)
    gpiochip1 [sx1509q] (17 lines)
    gpiochip2 [sx1509q] (17 lines)
    gpiochip3 [sx1509q] (17 lines)
    gpiochip4 [ftdi-cbus] (4 lines)
    gpiochip5 [ftdi-cbus] (4 lines)
    root@lec-mtk-i1200-ufs:~#

    or
    cat /sys/kernel/debug/gpio

    root@lec-mtk-i1200-ufs:~# cat /sys/kernel/debug/gpio
    gpiochip5: GPIOs 288-291, parent: usb/1-1.7:1.0, ftdi-cbus, can sleep:

    gpiochip4: GPIOs 292-295, parent: usb/5-1:1.0, ftdi-cbus, can sleep:

    gpiochip3: GPIOs 296-312, parent: i2c/4-003f, sx1509q, can sleep:
    gpio-301 ( |WIFI PD ) out hi

    gpiochip2: GPIOs 313-329, parent: i2c/4-003e, sx1509q, can sleep:

    gpiochip1: GPIOs 330-346, parent: i2c/3-003e, sx1509q, can sleep:

    gpiochip0: GPIOs 347-511, parent: platform/10005000.pinctrl, pinctrl_paris:

    GPIO instructions
  • To export the GPIO pin.

    Note:- The GPIO chip base number may differ for different modules. It is not necessary to be the same as below.

    echo N > export (N should replace with gpio chip base number)

    root@lec-mtk-i1200-ufs:/sys/class/gpio# echo 314 > export
    root@lec-mtk-i1200-ufs:/sys/class/gpio#
    GPIO instructions
  • To read the exported pin details, you can use the command cat

    cd gpioN       (N should replace with gpio chip base number)
    ls
    cat direction
    cat value

    root@lec-mtk-i1200-ufs:/sys/class/gpio# cd gpio314
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# ls
    active_low device direction edge power subsystem uevent value
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# cat direction
    in
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# cat value
    1
    GPIO instructions
  • To read the direction of a pin

    cat /sys/class/gpio/gpioN/direction  (N should replace with gpio chip base number)

    root@lec-mtk-i1200-ufs:~# cat /sys/class/gpio/gpio314/direction
    in
    root@lec-mtk-i1200-ufs:~#

    or

    cd /sys/class/gpio/gpioN
    cat direction

    root@lec-mtk-i1200-ufs:~# cd /sys/class/gpio/gpio314
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# cat direction
    in

  • To write the direction of a pin to input

    echo in > /sys/class/gpio/gpioN/direction  (N should replace with gpio chip base number)

    root@lec-mtk-i1200-ufs:~# echo in > /sys/class/gpio/gpio314/direction
    root@lec-mtk-i1200-ufs:~#

    or

    cd /sys/class/gpio/gpioN
    echo in> direction

    root@lec-mtk-i1200-ufs:~# cd /sys/class/gpio/gpio314
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# echo in> direction
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#

GPIO instructions
GPIO instructions

  • To write the direction of a pin to output

    echo out > /sys/class/gpio/gpioN/direction  (N should replace with gpio chip base number)


    root@lec-mtk-i1200-ufs:~# echo out > /sys/class/gpio/gpio314/direction
    root@lec-mtk-i1200-ufs:~#

    or

    cd /sys/class/gpio/gpioN
    echo out> direction


    root@lec-mtk-i1200-ufs:~# cd /sys/class/gpio/gpio314
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# echo out> direction
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#
GPIO instructions
  • To read the value of a pin

    cat /sys/class/gpio/gpioN/value    (N should replace with gpio chip base number)

    root@lec-mtk-i1200-ufs:~# cat /sys/class/gpio/gpio314/value
    0
    root@lec-mtk-i1200-ufs:~#

    or
    cd /sys/class/gpio/gpioN
    cat value

    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# cat value
    0
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#
  • To write the value of a pin to high

    Note: Make sure the direction is out when you are trying to change the value to high or low.

    echo 1 > /sys/class/gpio/gpioN/value     (N should replace with gpio chip base number)


    root@lec-mtk-i1200-ufs:~# echo 1 > /sys/class/gpio/gpio314/value
    root@lec-mtk-i1200-ufs:~#


    or
    cd /sys/class/gpio/gpioN
    echo 1 > value

    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# echo 1 > value
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#


  • To write the value of a pin to low

    Note: Make sure the direction is out when you are trying to change the value to high or low.

    echo 0 > /sys/class/gpio/gpioN/value

    root@lec-mtk-i1200-ufs:~# echo 0 > /sys/class/gpio/gpio314/value
    root@lec-mtk-i1200-ufs:~#

    or
    cd /sys/class/gpio/gpioN
    echo 0 > value

    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314# echo 0 > value
    root@lec-mtk-i1200-ufs:/sys/class/gpio/gpio314#
GPIO instructions

GPIO instructions

GPIO Pin Configurations

On CN1001 expansion connector E_GPIO and S_GPIO is available. These GPIO pins are mapped by to following numbers

S_GPIO:

S_GPIO_Name CN1001_Pin_Number Sysfs_Index
S_GPIO06_3V Pin7 466
S_GPIO07_3V Pin12 314
S_GPIO08_3V Pin11 315
S_GPIO09_3V Pin13 316
S_GPIO10_3V Pin15 317
S_GPIO11_3V Pin16 326
S_GPIO12_3V Pin18 327
S_GPIO13_3V Pin22 328

E_GPIO:

E_GPIO_Name CN1001_Pin_Number Sysfs_Index
E_GPIO1_0 Pin29 330
E_GPIO1_1 Pin31 331
E_GPIO1_2 Pin32 332
E_GPIO1_3 Pin33 333
E_GPIO1_4 Pin35 334
E_GPIO1_5 Pin36 335
E_GPIO1_6 Pin37 336
E_GPIO1_7 Pin38 337
E_GPIO1_8 Pin40 338