GPIO
GPIO pins are 'general purpose input/output pins', configurable as both input and outputs where needed. These pins form the most common interface to hook up your own hardware.
According to the hardware description, the maaxboard has no less than 5 x 32 = 160 GPIO pins. This is also visible to the linux system, when you look at the /sys/class/gpio directory:
# ls -lia /sys/class/gpio/
totaal 0
1946 drwxr-xr-x 2 root root 0 apr 20 16:53 .
10 drwxr-xr-x 64 root root 0 apr 20 16:53 ..
1947 --w------- 1 root root 4096 apr 20 16:46 export
6176 lrwxrwxrwx 1 root root 0 apr 20 16:53 gpiochip0 -> ../../devices/platform/30200000.gpio/gpio/gpiochip0
7192 lrwxrwxrwx 1 root root 0 apr 20 16:53 gpiochip128 -> ../../devices/platform/30240000.gpio/gpio/gpiochip128
6430 lrwxrwxrwx 1 root root 0 apr 20 16:53 gpiochip32 -> ../../devices/platform/30210000.gpio/gpio/gpiochip32
6684 lrwxrwxrwx 1 root root 0 apr 20 16:53 gpiochip64 -> ../../devices/platform/30220000.gpio/gpio/gpiochip64
6938 lrwxrwxrwx 1 root root 0 apr 20 16:53 gpiochip96 -> ../../devices/platform/30230000.gpio/gpio/gpiochip96
1948 --w------- 1 root root 4096 apr 20 16:46 unexport
Each chip is shown by its base address, so gpiochip0 is for gpio's 9 through 31, gpiochip32 for 32 to 63, etc.
As far as I could tell, only 2 chips are connected to the GPIO header with a couple of pins, these are named 'GPIO1' (for gpiochip0) and 'GPIO3' (for gpiochip64).
From the avnet hardware manual, I deducted the GPIO pin addressing; although the general layout of the 40-pin GPIO header follows the raspberry pi numbering, the internal numbers are quite different:
GPIO Pin | Pin name | Internal GPIO number | GPIO chip | /sys/class/gpio/gpio<xx> | Test result as output | Test result as input |
---|---|---|---|---|---|---|
7 | GPIO3_IO16 | 16 | 3 | 80 | OK | OK |
11 | GPIO3_IO17 | 17 | 3 | 81 | OK | OK |
13 | GPIO3_IO08 | 8 | 3 | 72 | NOT OK | NOT OK |
15 | GPIO3_IO09 | 9 | 3 | 73 | NOT OK | NOT OK |
19 | GPIO3_IO06 | 6 | 3 | 70 | reported as busy | reported as busy |
21 | GPIO3_IO07 | 7 | 3 | 71 | reported as busy | reported as busy |
22 | GPIO3_IO15 | 15 | 3 | 79 | OK | OK |
23 | GPIO3_IO00 | 0 | 3 | 64 | NOT OK | NOT OK |
24 | GPIO3_IO01 | 1 | 3 | 65 | NOT OK | NOT OK |
26 | GPIO3_IO02 | 2 | 3 | 66 | OK | OK |
29 | GPIO3_IO05 | 5 | 3 | 69 | OK | OK |
31 | GPIO3_IO10 | 10 | 3 | 74 | OK | OK |
32 | GPIO1_IO15 | 15 | 1 | 15 | OK | OK |
33 | GPIO1_IO13 | 13 | 1 | 13 | OK | OK |
36 | GPIO1_IO03 | 3 | 1 | 3 | OK | OK |
37 | GPIO3_IO11 | 11 | 3 | 75 | OK | OK |
I tested the GPIO bus #1 with the standard way of addressing gpios through the /sys/class interface:
- export the pin number to /sys/class/gpio/export
- now the gpio pin becomes available under /sys/class/gpio/gpio + pin number
- make the gpio pin an output by writing 'out' to /sys/class/gpio/gpioXX/direction
- now you can write values of 1 or 0 into '/sys/class/gpio/gpioXX/value
- clear the pin again by writing the pin number to /sys/class/gpio/unexport
Example for pin 13:
# ls -1 --color /sys/class/gpio
export
gpiochip0
gpiochip128
gpiochip32
gpiochip64
gpiochip96
unexport
# echo 13 > /sys/class/gpio/export
# ls -1 --color /sys/class/gpio
export
gpio13
gpiochip0
gpiochip128
gpiochip32
gpiochip64
gpiochip96
unexport
# echo out > /sys/class/gpio/gpio13/direction
# echo 0 > /sys/class/gpio/gpio13/value
# echo 1 > /sys/class/gpio/gpio13/value
# echo 13 > /sys/class/gpio/unexport
# ls -1 --color /sys/class/gpio
export
gpiochip0
gpiochip128
gpiochip32
gpiochip64
gpiochip96
unexport
In this way, I tested all three GPIO pins of the GPIO1 controller, and they all worked as expected.
The GPIO3 pins could also be used, by calculating the gpio number as follows:
gpio_number = (chip_number -1) * 32 + gpio port
For example, GPIO port 11 on gpio3 is: (3-1)*32 +11 = 75.
To test the GPIO as in input, the procedure is similar:
- export the pin number to /sys/class/gpio/export
- now the gpio pin becomes available under /sys/class/gpio/gpio + pin number
- make the gpio pin an input by writing 'in' to /sys/class/gpio/gpioXX/direction
- now you can read the value from '/sys/class/gpio/gpioXX/value, this should be an 0 or an 1, depending how the input is connected.
- To test whether it functions, connect the input either to GND (it should read 0) or to 3.3V (it should read 1).
- clear the pin again by writing the pin number to /sys/class/gpio/unexport
Not all GPIO pins were accessible this way, this is probably due to some drivers interfering.
So, except for these 6 pins (13, 15, 19, 21, 23 and 24), there are 10 GPIO pins usable from the 40-pin header, both as outputs (to drive LEDs or relays) and inputs. According to the hardware manual, there are 2 more pins available on the camera connector, but I lacked the cabling to be able to test those.
Unlike the raspberry pi, the 'other' GPIO pins, which are all mapped to other functions like i2c and uarts and such, cannot be easily identified in this way; it would be nice to be able to use those if you do not need them for other things. I counted 12 of them, so in theory you could have 22 to 28 GPIO pins available, if both the unusable pins and the 'mapped' pins could be configured.
Conclusion
With the exception of the 6 mysterious pins and the 12 'mapped' pins, all the GPIO pins worked as I expected, and had fun figuring out how to address them and test them. In practice, I hardly use more than a few pins anyway, and prefer to use i2c or other means if I really need more pins. So for me, the maaxboard's GPIO capability is perfectly acceptable.