Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:techref:hardware:port.gpio [2019/06/18 16:21] – old revision restored (2018/10/13 10:58) bobafetthotmail | docs:techref:hardware:port.gpio [2023/07/20 01:47] (current) – Add info box about gpiod-tools, gpio sysfs has been marked obsolete and won't work correctly djfe | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== GPIO ====== | ====== GPIO ====== | ||
| Read [[wp> | Read [[wp> | ||
| - | |||
| * [[docs: | * [[docs: | ||
| - | * [[toh/tp-link/tl-wr1043nd# | + | * [[toh:tp-link:tl-wr1043nd# |
| - | * [[/ | + | * [[https:// |
| ===== Hardware ===== | ===== Hardware ===== | ||
| Line 33: | Line 31: | ||
| | [[https:// | | [[https:// | ||
| - | You can connect 5V digital signal sensors if you use a voltage | + | You can connect 5V digital signal sensors if you use a voltage |
| - | Sensor signal output is in the 5V range, connect it to the voltage | + | Sensor signal output is in the 5V range, connect it to the voltage |
| \\ \\ {{: | \\ \\ {{: | ||
| Line 43: | Line 41: | ||
| Many times some GPIOs cannot be controlled by the kernel because they are multiplexed, | Many times some GPIOs cannot be controlled by the kernel because they are multiplexed, | ||
| - | * Example 1: on the Broadcom BCM6328 SoC, GPIO pins 25, 26, 27 and 28 are used to indicate the LAN activity with hardware controlled LEDs. The memory register for setting this multiplexing is at 0x1000009C address, 64bits wide. Let's read it in OpenWrt\\ | + | * Example 1: on the Broadcom BCM6328 SoC, GPIO pins 25, 26, 27 and 28 are used to indicate the LAN activity with hardware controlled LEDs. The memory register for setting this multiplexing is at 0x1000009C address, 64bits wide. Let's read it in OpenWrt\\ <code> |
| - | 0x0154000000000000</ | + | 0x0154000000000000</ |
| - | * Example 2: on the Atheros AR7240 SoC, GPIO pins 6, 7 and 8 are used by the JTAG interface. The memory register for AR7240 GPIO pinmux is at 0x18040028 address, 32 bits wide. Let's read it:\\ '' | + | * Example 2: on the Atheros AR7240 SoC, GPIO pins 6, 7 and 8 are used by the JTAG interface. The memory register for AR7240 GPIO pinmux is at 0x18040028 address, 32 bits wide. Let's read it:\\ <code> |
| - | 0x48002</ | + | 0x48002</ |
| ==== GPIO Interrupts ==== | ==== GPIO Interrupts ==== | ||
| GPIO interrupts are useful when a GPIO is used as input and you need to manage high signal frequencies. Without interrupts, GPIO inputs must be managed using the **polling** method. With polling you cannot manage signal inputs with high frequencies, | GPIO interrupts are useful when a GPIO is used as input and you need to manage high signal frequencies. Without interrupts, GPIO inputs must be managed using the **polling** method. With polling you cannot manage signal inputs with high frequencies, | ||
| Line 58: | Line 56: | ||
| ===== Software ===== | ===== Software ===== | ||
| + | <WRAP round info 100%> | ||
| + | **The GPIO SYSFS interface has been marked as obsolete in 2015. I couldn' | ||
| + | |||
| + | The new interface is the linux GPIO character device. One way to access it is [[https:// | ||
| + | |||
| + | You can install it with the [[: | ||
| + | |||
| + | <code bash> | ||
| + | opkg install gpiod-tools</ | ||
| + | |||
| + | A good article on how to use the new CLI and why we should move on: [[https:// | ||
| + | |||
| + | The biggest differences are: | ||
| + | * The new interface isn't stateless like the old one. Processes are able to take exclusive control over a gpio line now | ||
| + | * There is a character device / | ||
| + | * TODO | ||
| + | As I said: This page needs an overhaul. This info box is just to prevent people from wasting their time on a deprecated ABI. | ||
| + | </ | ||
| + | |||
| In linux GPIOs can be accessed through GPIO SYSFS interface: **/ | In linux GPIOs can be accessed through GPIO SYSFS interface: **/ | ||
| Line 185: | Line 202: | ||
| done | done | ||
| </ | </ | ||
| + | |||
| - Measure continuosuly the voltage of the pin where you suspect there is a GPIO wired, with a multimeter or another device. | - Measure continuosuly the voltage of the pin where you suspect there is a GPIO wired, with a multimeter or another device. | ||
| - Put all GPIOs on HIGH state '' | - Put all GPIOs on HIGH state '' | ||
| Line 193: | Line 211: | ||
| - Repeat until you have identified the gpio number | - Repeat until you have identified the gpio number | ||
| + | ==== script "blink all" ==== | ||
| + | |||
| + | Another script to look for GPIO connected to LED | ||
| + | <code bash> | ||
| + | #!/bin/sh | ||
| + | # Modified from https:// | ||
| + | echo GPIO LED Test | ||
| + | echo | ||
| + | echo Example: $0 3s 0 1 | ||
| + | echo leave gpio range blank to test all GPIOs. | ||
| + | echo | ||
| + | wait=${1: | ||
| + | for GPIOCHIP in / | ||
| + | BASE=$(cat ${GPIOCHIP}base) | ||
| + | SIZE=$(cat ${GPIOCHIP}ngpio) | ||
| + | MAX=$(($BASE+$SIZE-1)) | ||
| + | gpio_end=${3: | ||
| + | [ -z " | ||
| + | while [ $gpio -ge $BASE -a $gpio -le $MAX -a $gpio -le $gpio_end ] ; do | ||
| + | # Save original value if needed | ||
| + | if [ -d / | ||
| + | DIRECTION=$(cat / | ||
| + | UNEXPORT=0 | ||
| + | VALUE=$(cat / | ||
| + | else | ||
| + | echo $gpio > / | ||
| + | UNEXPORT=1 | ||
| + | DIRECTION="" | ||
| + | VALUE="" | ||
| + | fi | ||
| + | if [ -d / | ||
| + | echo out > / | ||
| + | | ||
| + | echo " | ||
| + | echo 0 > / | ||
| + | sleep $wait | ||
| + | | ||
| + | echo " | ||
| + | echo 1 > / | ||
| + | sleep $wait | ||
| + | | ||
| + | # Restore original value | ||
| + | [ ! -z " | ||
| + | [ ! -z " | ||
| + | [ " | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | | ||
| + | gpio=$((gpio+1)) | ||
| + | done | ||
| + | done | ||
| + | </ | ||
| + | - Run the script, the script can loop all GPIOs | ||
| + | - Look at the LED and record the number printed when LED is on or off | ||
| + | |||
| Note: some GPIOs may return an error because they' | Note: some GPIOs may return an error because they' | ||
| + | |||
| ===== Finding GPIO pins (input) on the PCB ===== | ===== Finding GPIO pins (input) on the PCB ===== | ||
| - | Sometimes you do not know where the physical GPIO pins (input) are on your device' | + | ==== script |
| + | Sometimes you do not know where the physical GPIO pins (input) are on your device' | ||
| <code bash> | <code bash> | ||
| Line 224: | Line 300: | ||
| - Press ctrl-c to stop the script, then check which GPIOs have been created: '' | - Press ctrl-c to stop the script, then check which GPIOs have been created: '' | ||
| + | ==== script "gpio in" ==== | ||
| + | Another script which check each GPIO one-by-one | ||
| - | ===== Links ===== | + | <code bash> |
| + | #!/bin/sh | ||
| + | # Modified from https:// | ||
| + | echo GPIO Button Test | ||
| + | echo | ||
| + | echo Example: $0 0 1 | ||
| + | echo leave gpio range blank to test all GPIOs. | ||
| + | echo | ||
| + | for GPIOCHIP in / | ||
| + | BASE=$(cat ${GPIOCHIP}base) | ||
| + | SIZE=$(cat ${GPIOCHIP}ngpio) | ||
| + | MAX=$(($BASE+$SIZE-1)) | ||
| + | gpio_end=${2: | ||
| + | [ -z " | ||
| + | while [ $gpio -ge $BASE -a $gpio -le $MAX -a $gpio -le $gpio_end ] ; do | ||
| + | # Save original value if needed | ||
| + | if [ -d / | ||
| + | DIRECTION=$(cat / | ||
| + | UNEXPORT=0 | ||
| + | else | ||
| + | echo $gpio > / | ||
| + | UNEXPORT=1 | ||
| + | DIRECTION="" | ||
| + | fi | ||
| + | if [ -d / | ||
| + | echo in > / | ||
| + | echo " | ||
| + | |||
| + | # Restore original value | ||
| + | [ ! -z " | ||
| + | [ " | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | |||
| + | gpio=$((gpio+1)) | ||
| + | done | ||
| + | done | ||
| + | </ | ||
| - | * [[http:// | + | |
| + | - Hold a button and run again, release only after the script has been finished | ||
| + | - Compare the changed GPIO value which corresponding to the button held | ||
| + | ===== Links ===== | ||
| + | | ||
| * [[http:// | * [[http:// | ||
| - | ===== Tags ===== | + | ===== Devices |
| - | [[meta:tags|How to add tags]] | + | The list of related devices: |
| + | {{tagpage> | ||
| - | {{tag> | ||