GPIO

General-Purpose Input/Output (GPIO) pins can be configured as either inputs or outputs. Many signals on the phyCORE-Connector can be used as GPIOs through multiplexing. The AM62x processor features five independent GPIO modules. For detailed information about the phyCORE-AM62x GPIO interface, please refer to the GPIO section in the Hardware Manual

GPIO Signal Names and Chip Mapping

GPIOn_x is generic name used to describe a GPIO signal, where n represents the specific GPIO module and x represents one of the input/output signals associated with the module. Usually you find this names in the schematics and in comments in our device trees in the muxing section.

The AM62x provides three GPIO modules:

  • GPIO0

  • GPIO1

  • MCU_GPIO0

Linux represents these modules as gpiochips. You can list them using the gpiodetect command:

phyboard-lyra-am62xx-3:~# gpiodetect
gpiochip0 [tps65219-gpio] (3 lines)
gpiochip1 [4201000.gpio] (24 lines) # MCU_GPIO0
gpiochip2 [600000.gpio] (92 lines)  # GPIO0
gpiochip3 [601000.gpio] (52 lines)  # GPIO1
gpiochip4 [pcf8574] (8 lines)

The second column shows the hardware address of each GPIO module. In the device tree, these GPIOs are accessed using node labels:

Note

GPIO chip numbers may change between system boots. For consistent numbering, configure udev rules.

Active GPIO Signals

The following command shows GPIO signals that are currently allocated by kernel drivers. These GPIOs are already in use and attempting to access them with gpioget or gpioset will result in a “Device or resource busy” error.

See the allocated GPIO signals by running:

phyboard-lyra-am62xx-3:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 512-514, parent: i2c/0-0030, tps65219-gpio, can sleep:

gpiochip1: GPIOs 515-538, parent: platform/4201000.gpio, 4201000.gpio:

gpiochip2: GPIOs 539-630, parent: platform/600000.gpio, 600000.gpio:
 gpio-552 (                    |green:heartbeat     ) out lo
 gpio-571 (                    |led-1               ) out lo

gpiochip3: GPIOs 631-682, parent: platform/601000.gpio, 601000.gpio:
 gpio-654 (                    |home                ) in  lo

gpiochip4: GPIOs 683-690, parent: i2c/1-0021, pcf8574, can sleep:
 gpio-684 (GPIO1_CAN0_nEN      |standby             ) out lo
 gpio-685 (GPIO2_LED2          |led-2               ) out lo
 gpio-686 (GPIO3_LVDS_GPIO     )
 gpio-687 (GPIO4_BUT2          |menu                ) in  lo IRQ
 gpio-688 (GPIO5_LVDS_BKLT_EN  )
 gpio-689 (GPIO6_ETH1_USER_RESE)
 gpio-690 (GPIO7_AUDIO_USER_RES)

Using GPIOs

To access GPIOs from userspace applications, use the libgpiod library. This library provides tools for interacting with Linux GPIO devices. Here are some common usage examples:

  • List all available GPIO chips:

phyboard-lyra-am62xx-3:~# gpiodetect
gpiochip0 [tps65219-gpio] (3 lines)
gpiochip1 [4201000.gpio] (24 lines) # MCU_GPIO0
gpiochip2 [600000.gpio] (92 lines)  # GPIO0
gpiochip3 [601000.gpio] (52 lines)  # GPIO1
gpiochip4 [pcf8574] (8 lines)
  • Display detailed GPIO chip information (names, consumers, direction, active state, and flags):

phyboard-lyra-am62xx-3:~# gpioinfo -c gpiochip2
  • Read the value of a GPIO (e.g GPIO 36 from chip2):

phyboard-lyra-am62xx-3:~# gpioget -c gpiochip2 36
  • Set the value of GPIO 36 on chip2 to 0 and exit tool:

phyboard-lyra-am62xx-3:~# gpioset -z -c gpiochip2 36=0

Note

Interacting with a Signal as GPIO requires a proper muxing. The signal needs to be muxed in mux mode 7 (GPIO).

GPIOs via sysfs

Warning

Accessing GPIOs via sysfs is deprecated. We strongly encourage using libgpiod instead.

Sysfs GPIO access is no longer enabled by default. To enable it, enable CONFIG_EXPERT & CONFIG_GPIO_SYSFS in the kernel configuration.

Using LEDs

The phyBOARD-Lyra AM62x features several user-controllable LEDs that are connected to GPIO pins. While these LEDs can be controlled through the standard GPIO interface, Linux provides a dedicated LED subsystem that offers a more convenient way to manage them.

phyCORE-AM62x UI

LED Control Interface

The LED subsystem is accessible through the sysfs interface at /sys/class/leds/. Each LED has its own directory containing control files:

  • brightness: Write values to control the LED state
    • 0 turns the LED off

    • Any non-zero value turns the LED on

  • max_brightness: Read-only file showing the maximum brightness value

  • trigger: Allows setting automatic triggers (e.g., heartbeat, disk activity)

Note

While the interface supports brightness levels, most onboard LEDs are simple on/off LEDs without hardware brightness control. Any non-zero brightness value will simply turn them on.

Available LEDs

To list all available LEDs on your system:

phyboard-lyra-am62xx-3:~# ls /sys/class/leds/
green:heartbeat@  led-1@  led-2@  mmc0::@  mmc1::@

Controlling LEDs

You can control LEDs using simple shell commands:

  • To toggle the LEDs ON:

    phyboard-lyra-am62xx-3:~# echo 255 > /sys/class/leds/led-1/brightness
    
    • To toggle the LEDs OFF:

    phyboard-lyra-am62xx-3:~# echo 0 > /sys/class/leds/led-1/brightness
    

Advanced Usage

For more details about LED configuration, refer to the Linux kernel documentation at https://www.kernel.org/doc/Documentation/leds/leds-class.txt

  • Set LED triggers (e.g., for heartbeat effect):

    phyboard-lyra-am62xx-3:~# echo heartbeat > /sys/class/leds/green\:heartbeat/trigger
    
  • Disable LED trigger:

    phyboard-lyra-am62xx-3:~# echo none > /sys/class/leds/green\:heartbeat/trigger
    

Using Buttons

This section describes how to interact with GPIO-based buttons on the board using the available interface and tools. The system provides an input event device for managing button presses.

Button events are accessible through the Linux input subsystem via the evdev interface at /dev/input/event0. The buttons are mapped to standard input events KEY_HOME and KEY_MENU. You can monitor button events in real-time using the evtest utility as shown in the example below.

For more details on the Linux input subsystem, refer to the kernel documentation at https://www.kernel.org/doc/Documentation/input/input.txt.

phyboard-lyra-am62xx-3:~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:      keys
/dev/input/event1:      tps65219-pwrbutton
Select the device event number [0-1]: 0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 102 (KEY_HOME)
    Event code 139 (KEY_MENU)
Key repeat handling:
 Repeat type 20 (EV_REP)
   Repeat code 0 (REP_DELAY)
     Value    250
   Repeat code 1 (REP_PERIOD)
     Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 1709110401.718931, type 1 (EV_KEY), code 139 (KEY_MENU), value 1
Event: time 1709110401.718931, -------------- SYN_REPORT ------------
Event: time 1709110401.910986, type 1 (EV_KEY), code 139 (KEY_MENU), value 0
Event: time 1709110401.910986, -------------- SYN_REPORT ------------
Event: time 1709110402.549982, type 1 (EV_KEY), code 102 (KEY_HOME), value 1
Event: time 1709110402.549982, -------------- SYN_REPORT ------------
Event: time 1709110402.741037, type 1 (EV_KEY), code 102 (KEY_HOME), value 0
Event: time 1709110402.741037, -------------- SYN_REPORT ------------