The phyCORE-AM57x SOM brings out a selection of GPIOs and you can access many of these signals through some pre-made LED/Button circuits and with the help of the PHYTEC Expansion board (PCM-957)This guide walks through the basic steps of toggling and reading the state of these IO interfaces.

This section of the guide will walk through the use of the pre-made LED circuits populated directly on the Carrier Board and SOM. These outputs have been pre-configured in the device tree for use. 

User LEDs

LEDLocation
/sys/class/leds/am57xx-phycore-som\:redSOM (D1)
/sys/class/leds/am57xx-phycore-som\:greenSOM (D2)
/sys/class/leds/am57xx-pcm-948\:usr1/CB (LED1)
/sys/class/leds/am57xx-pcm-948\:usr2/CB (LED2)

Toggle Off

In order to assume control over the LEDs, first toggle them off with the following command. This example will use the red LED located on the SOM but the following can be performed with any of the LEDs if the correct sysfs path is specified.

Target (Linux)

echo 0 > /sys/class/leds/am57xx-phycore-som\:red/brightness
CODE

Toggle On

Now toggle the LED back on:

Target (Linux)

echo 1 > /sys/class/leds/am57xx-phycore-som\:red/brightness
CODE
 Advanced Steps to Impress your Mom!
  • To create a script that automatically blinks the LED, open a text editor: 

    Linux

    vi ~/blink.sh
    CODE
  • Edit the contents of the new file to reflect the code below and save the file: 

    Linux

    #!/bin/sh
    echo 0 > /sys/class/leds/am57xx-phycore-som\:red/brightness
    echo 0 > /sys/class/leds/am57xx-phycore-som\:green/brightness
    
    for i in `seq 1 10`; do
    echo 1 > /sys/class/leds/am57xx-phycore-som\:red/brightness
    echo 0 > /sys/class/leds/am57xx-phycore-som\:green/brightness
    sleep 1
    echo 0 > /sys/class/leds/am57xx-phycore-som\:red/brightness
    echo 1 > /sys/class/leds/am57xx-phycore-som\:green/brightness
    sleep 1
    done
    CODE

    The vi text editor begins in "Command Mode" and you must first hit the 'i' key in order to enter "Insert Mode". Using the arrow keys to navigate, make the necessary changes and then hit ESC to go back to "Command mode". Now enter ":wq" to write the file and quit.

  • Make your file executable:

    Linux

    chmod +x ~/blink.sh
    CODE
  • Now run the script: 

    Linux

    ~/blink.sh
    CODE


User Button

This section of the guide will walk through the use of a user made Push Button populated directly onto the PHYTEC Expansion Board (PCM-957).

  • With the phyCORE-AM57x powered off and with the power supply removed, hook up a through-hole push button to the pin 23C and to the supply rail at pin 51C. Use the following circuit diagram for reference: 

     

    GPIO4_20 is an undefined signal in the device tree and therefore will default to its reset state, which internally pulls down the pin. Thus, we need to pull the signal high when the button is pressed.

  • Once wired up, reconnect the power supply and boot into Linux.
  • Use the following command to export the GPIO signal in sysfs: 

    Target (Linux)

    echo 116 > /sys/class/gpio/export
    CODE

    For your AM57x SOM, in order to match signal names in hardware to the device name in sysfs , use the following equation:


    Hardware Signal = GPIO(Bank)_(num)

    sysfs GPIO Device = (Bank -1)*32 + num


    For example:

    Hardware Signal = GPIO4_20

    sysfs GPIO Device = (4 - 1)*32 + 20 = 116

    GPIO4_20 is represented as GPIO116 in sysfs

  • Set GPIO4_20 as an input: 

    Target (Linux)

    echo in > /sys/class/gpio/gpio116/direction
    CODE
  • Lets try polling the state of the GPIO4_20 signal: 

    Target (Linux)

    cat /sys/class/gpio/gpio116/value
    CODE

    Expected Output

    root@am57xx-phycore-kit:~# cat /sys/class/gpio/gpio116/value
    0
    CODE
  • Now try polling the state of the button again while pressing and holding the push button we just wired up! You should see that the state of the signal went from 0 to a 1.