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 PinPin nameInternal GPIO numberGPIO chip/sys/class/gpio/gpio<xx>Test result as outputTest result as input
7GPIO3_IO1616380OKOK
11GPIO3_IO1717381OKOK
13GPIO3_IO088372NOT OKNOT OK
15GPIO3_IO099373NOT OKNOT OK
19GPIO3_IO066370reported as busyreported as busy
21GPIO3_IO077371reported as busyreported as busy
22GPIO3_IO1515379OKOK
23GPIO3_IO000364NOT OKNOT OK
24GPIO3_IO011365NOT OKNOT OK
26GPIO3_IO022366OKOK
29GPIO3_IO055369OKOK
31GPIO3_IO1010374OKOK
32GPIO1_IO1515115OKOK
33GPIO1_IO1313113OKOK
36GPIO1_IO03313OKOK
37GPIO3_IO1111375OKOK

 

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.