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.
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.
echo 0 > /sys/class/leds/am57xx-phycore-som\:red/brightness
Now toggle the LED back on:
echo 1 > /sys/class/leds/am57xx-phycore-som\:red/brightness
To create a script that automatically blinks the LED, open a text editor:
Edit the contents of the new file to reflect the code below and save the file:
#!/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 doneCODE
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:
chmod +x ~/blink.shCODE
Now run the script:
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:
echo 116 > /sys/class/gpio/exportCODE
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
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:
echo in > /sys/class/gpio/gpio116/directionCODE
Lets try polling the state of the GPIO4_20 signal:
root@am57xx-phycore-kit:~# cat /sys/class/gpio/gpio116/value 0CODE
- 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.