GPIO
The phyCORE-AM65x SOM brings out a selection of GPIOs to the connectors. On the development kit you can access many of these signals through the PHYTEC Expansion Board (PCM-957). This guide walks through the basic steps of toggling and reading the state of these IO interfaces.
Connect to the GPIOs
GPIO1_50 and GPIO0_73 have been selected for this example, and are accessible at the expansion connector. The table below gives a brief description of the two selected signals:
GPIO |
Expansion Board Pin # |
Description |
---|---|---|
X_GPIO1_50 |
21C |
Expansion_button (in device tree) Digital input, internal pull down resistor |
X_GPIO0_73 |
25C |
Expansion_led (in device tree, needs updating) Digital output, 1.8V when set HIGH |
Set up Hardware Configuration
You can wire up a test circuit on the expansion board such as the following:
Set up Software Configuration
In order to be accessible in Linux, the GPIOs need to be configured in the Linux device tree. PHYTEC has provided a sample device tree overlay, in the boot directory of the root file system, which configures expansion connector interfaces used in this Peripheral Guide. To enable this device tree overlay:
The device tree overlay is set in U-Boot.
To enter U-Boot, hit any key within 3 seconds of powering on the hardware to halt autoboot.
Clear the “default_overlays” variable and modify the “extra_overlays” variable to point to the sample dtbo: “k3-am65xx-phytec-expansion-sample.dtbo”. The “default_overlays” variable needs to be cleared because it is set to k3-am65xx-phytec-lcd-018.dtbo which conflicts with the sample. (the code will need to be updated to use GPIO_73)
setenv default_overlays setenv extra_overlays k3-am65xx-phytec-expansion-sample.dtbo saveenv
To exit U-Boot and continue booting into Linux, type boot
boot
Warning
The Expansion Sample overlay k3-am65xx-phytec-expansion-sample.dtbo conflicts with the LCD-018 overlay due to the PWM being used for backlight in the LCD-018. Make sure to disconnect the display when using this overlay before powering on the development kit.
Access GPIOs in Linux
LED
Set the pin high and turn on the LED:
echo 1 > /sys/class/leds/expansion_led/brightness
Set the pin low and turn off the LED
echo 0 > /sys/class/leds/expansion_led/brightness
Advanced steps to impress your mom!
To create a script that automatically blinks the LED, open a text editor:
vi ~/blink.sh
Edit the contents of the new file to reflect the code below and save the file: .. tip:: 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.
Pro Tip: Once in “Insert Mode”, copy and paste the file contents to save you some effort!
#!/bin/sh
for i in `seq 1 10`; do
echo 1 > /sys/class/leds/expansion_led/brightness
sleep 1
echo 0 > /sys/class/leds/expansion_led/brightness
sleep 1
done
Make your file executable:
chmod +x ~/blink.sh
Now run the script:
~/blink.sh
Revert to the Default Software Configuration
This guide requires disabling the LCD-018 and enabling a sample expansion overlay. In order to revert back to the default overlay settings, the following needs to be run in U-Boot:
To enter U-Boot, hit any key within 3 seconds of powering on the hardware to halt autoboot.
env default -f -a saveenv