Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:techref:hardware:port.gpio [2019/09/03 13:52] – [script "static"] add another script brianpowdocs: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 31: Line 31:
 | [[https://github.com/wendlers/rcswitch-kmod|rcswitch-kmod]] | rcswitch-kmod | ☐ | 433 MHz RC power outlets (switches) | | [[https://github.com/wendlers/rcswitch-kmod|rcswitch-kmod]] | rcswitch-kmod | ☐ | 433 MHz RC power outlets (switches) |
  
-You can connect 5V digital signal sensors if you use a voltage devider to get a 3.3V range signal.You need to get acces to GND and 5V-power from the router and connect the sensor to them. +You can connect 5V digital signal sensors if you use a voltage divider to get a 3.3V range signal.You need to get acces to GND and 5V-power from the router and connect the sensor to them. 
-Sensor signal output is in the 5V range, connect it to the voltage devider!+Sensor signal output is in the 5V range, connect it to the voltage divider!
 \\ \\ {{:media:voltagedividergpio.jpg?200|}} {{:media:5vsignal.jpg?200|}}\\ \\ \\ \\ {{:media:voltagedividergpio.jpg?200|}} {{:media:5vsignal.jpg?200|}}\\ \\
  
Line 41: Line 41:
 Many times some GPIOs cannot be controlled by the kernel because they are multiplexed, and they are not acting as GPIOs. It might be possible to undo the multiplexing by writing some particular software programmable register settings, and then recover the GPIO functionality. But probably on most cases those GPIOs were multiplexed for some good reason, like using a [[docs:techref:hardware:soc|SoC]] pin  for a signal on an ethernet phy, SPI, PCI, UART or another purpose. Many times some GPIOs cannot be controlled by the kernel because they are multiplexed, and they are not acting as GPIOs. It might be possible to undo the multiplexing by writing some particular software programmable register settings, and then recover the GPIO functionality. But probably on most cases those GPIOs were multiplexed for some good reason, like using a [[docs:techref:hardware:soc|SoC]] pin  for a signal on an ethernet phy, SPI, PCI, UART or another purpose.
  
-  * 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\\ ''<color grey>root@OpenWrt:/# devmem 0x1000009C 64 +  * 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>root@OpenWrt:/# devmem 0x1000009C 64 
-0x0154000000000000</color>''\\ {{:media:doc:hardware:bcm6328-lan-led_pinmux-bits.png?nolink|}}\\ These enabled bits are enabling every LAN LED to be controlled by hardware, therefore they cannot be controlled as regular GPIO's\\  Let's disable this multiplexing for all LEDs\\ ''<color grey>root@OpenWrt:/# devmem 0x1000009C 64 0x0</color>''\\ Now we can export these GPIOs and control them via software.+0x0154000000000000</code>\\ {{:media:doc:hardware:bcm6328-lan-led_pinmux-bits.png?nolink|}}\\ These enabled bits are enabling every LAN LED to be controlled by hardware, therefore they cannot be controlled as regular GPIO's\\  Let's disable this multiplexing for all LEDs\\ <code>root@OpenWrt:/# devmem 0x1000009C 64 0x0</code>\\ Now we can export these GPIOs and control them via software.
  
-  * 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:\\ ''<color grey>root@OpenWrt:/# devmem 0x18040028 32 +  * 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>root@OpenWrt:/# devmem 0x18040028 32 
-0x48002</color>''\\ The bit0 disables JTAG multiplexig, then we must set this bit to 1, in other words, write the value 0x48003\\ ''<color grey>root@OpenWrt:/# devmem 0x18040028 32 0x48003</color>''\\ Now we can control these GPIO pins (GPIO6, GPIO7 and GPIO8)+0x48002</code>\\ The bit0 disables JTAG multiplexing, then we must set this bit to 1, in other words, write the value 0x48003\\ <code>root@OpenWrt:/# devmem 0x18040028 32 0x48003</code>\\ Now we can control these GPIO pins (GPIO6, GPIO7 and GPIO8)
 ==== 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, but still can be used for simple tasks like reading the input on the device buttons.  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, but still can be used for simple tasks like reading the input on the device buttons. 
Line 56: Line 56:
  
 ===== Software ===== ===== Software =====
 +<WRAP round info 100%>
 +**The GPIO SYSFS interface has been marked as obsolete in 2015. I couldn't get the following scripts to work. This page needs an overhaul.**
 +
 +The new interface is the linux GPIO character device. One way to access it is [[https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README|libgpiod]].
 +
 +You can install it with the [[:packages:pkgdata:gpiod-tools]] package like this:
 +
 +<code bash>opkg update
 +opkg install gpiod-tools</code>
 +
 +A good article on how to use the new CLI and why we should move on: [[https://www.thegoodpenguin.co.uk/blog/stop-using-sys-class-gpio-its-deprecated/|Stop using /sys/class/gpio – it’s deprecated]]
 +
 +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 /dev/gpiochipX for each gpio chip found in the system
 +  * 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.
 +</WRAP>
 +
 In linux GPIOs can be accessed through GPIO SYSFS interface: **/sys/class/gpio/** In linux GPIOs can be accessed through GPIO SYSFS interface: **/sys/class/gpio/**
  
Line 191: Line 210:
   - Cut again the new range.   - Cut again the new range.
   - 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 Another script to look for GPIO connected to LED
Line 249: Line 270:
  
 ===== Finding GPIO pins (input) on the PCB ===== ===== Finding GPIO pins (input) on the PCB =====
 +
 +==== script "gpio in" ====
 +
 Sometimes you do not know where the physical GPIO pins (input) are on your device's PCB. In that case, you can use this little script and see screen to find the input. Sometimes you do not know where the physical GPIO pins (input) are on your device's PCB. In that case, you can use this little script and see screen to find the input.
  
Line 276: Line 300:
   - Press ctrl-c to stop the script, then check which GPIOs have been created: ''find /sys/class/gpio/gpio*''   - Press ctrl-c to stop the script, then check which GPIOs have been created: ''find /sys/class/gpio/gpio*''
  
-Another script+==== script "gpio in" ==== 
 + 
 +Another script which check each GPIO one-by-one
  
 <code bash> <code bash>
Line 322: Line 348:
   - Compare the changed GPIO value which corresponding to the button held   - Compare the changed GPIO value which corresponding to the button held
 ===== Links ===== ===== Links =====
-  * [[http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/gpio|Kernel gpio documentation]]+  * [[https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/gpio|Kernel gpio documentation]]
   * [[http://www.mjmwired.net/kernel/Documentation/gpio.txt|other kernel gpio doc]]   * [[http://www.mjmwired.net/kernel/Documentation/gpio.txt|other kernel gpio doc]]
  
  • Last modified: 2019/09/03 13:52
  • by brianpow