Although the MinnowBoard Max has a SATA port like a normal PC, it also has nice IO lines like a Raspberry Pi. The easiest pins to use are on a 26-pin 0.1" DIL header, whose pinout1 is shown on the eLinux website.
sysfs
If the proper kernel modules are installed, you can access the GPIO lines from userspace through devices in /sys.
Happily this is well documented in the kernel sources,2 but there is less abstract documentation3 on the eLinux website.
Sadly though the stock Ubuntu and Mint kernels do not include the relevant devices, so you will probably end up compiling your own.4 As Peter Ogden notes,5 the key configuration settings are:
CONFIG_PINCTRL_BAYTRAIL=y
CONFIG_GPIOLIB=y
CONFIG_GPIO_SYSFS=y
Thanks to Peter for pointing this out.
You can also grab the config I used6 from GitHub.
GPIO numbering
GPIO numbering changed between versions 3.17 and 3.18 of the kernel. The discussions below assume the latter, but you can adjust them to the old world order by subtracting 256.
Having compiled a new kernel, and rebooted into it, you can see the GPIO entries in /sys:
# ls /sys/class/gpio/
export gpiochip338/ gpiochip382/ gpiochip410/ unexport
Each gpiochip entry corresponds to a bank of GPIO pins.
We can find out more about the GPIO banks from sysfs:
# cat /sys/class/gpio/gpiochip*/base
338
382
410
# cat /sys/class/gpio/gpiochip*/ngpio
44
28
102
So, for example, we can see that there is a block of 44 GPIO pins starting at GPIO 338.
Hello Blinky
Pin 25 on the DIL header is easy to identify, so let’s connect an LED between there and Ground (with a suitable series resistor). Pin 25 is labelled (on the schematic7) as GPIO_S5_2, which can be identified as the third pin in the block of 44. For me, that block starts at GPIO 338, so my pin 25 corresponds to GPIO 340.
Having sorted out the hardware, we can flash the LED thus:
# echo 340 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio340/direction
# echo 0 > /sys/class/gpio/gpio340/value
# echo 1 > /sys/class/gpio/gpio340/value
# echo 0 > /sys/class/gpio/gpio340/value
# echo 1 > /sys/class/gpio/gpio340/value
# echo 0 > /sys/class/gpio/gpio340/value
# echo 1 > /sys/class/gpio/gpio340/value
...
Similarly, we can work out that pin 26 of the header corresponds to an offset of 54 within the block of 102 GPIO lines. Given the base of 410, this makes it GPIO 464.
Thus to interpret the pinout on the eLinux site:
- GPIO 8x have an implied base of 82;
- GPIO 2xx have an implied base of 154.
The gory details
All the GPIO numbers jumped by 256 when the kernel reached version 3.18, which caused me some confusion. The notes below might be helpful if it happens again.
- On the schematic8 trace the hardware pin the the CPU, and note the ball number. For example pin 26 on the DIL header goes to ILB_8254_SPKR on ball BH12.
- Look up the ball in table 142 of the E38xx datasheet9 For example, ball BH12 is associated with GPIO_S0_SC[054].
- SC stands for South Core, which is the block of 102 GPIO lines. On my board these start at GPIO 410. 54 is the offset, so pin 26 on the DIL header is GPIO 464.
Let’s try another. Header pin 25 connects to ball C18 which is GPIO_S5[02]. S5 is the block of 44 GPIO lines, which starts at GPIO 338 on my board. Thus, pin 25 is GPIO 340.
Adafruit Python GPIO library
I have hacked support for sysfs driven GPIO into the Adafruit Python GPIO Library.10 This lets you flash LEDs thus:
import Adafruit_GPIO as GPIO
import time
gpio = GPIO.get_platform_gpio()
pin = 338
gpio.setup(pin, GPIO.OUT)
gpio.output(pin, 1)
time.sleep(0.5)
gpio.output(pin, 0)
time.sleep(0.5)
You can get the library from GitHub11 but be warned: it’s only a proof of concept and not production quality!
References
- 1. http://www.elinux.org/MinnowBoard:MinnowMax#Low_Speed_Expansion_.28Top.29
- 2. https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
- 3. http://elinux.org/GPIO
- 4. ./kernel-cookbook.html
- 5. http://minnowboard.57273.x6.nabble.com/MinnowBoard-MinnowBoard-MAX-getting-started-with-GPIO-tp736p743.html
- 6. https://github.com/mjoldfield/seabass/blob/master/config
- 7. http://www.elinux.org/images/f/fd/MinnowMax_RevA1_sch.pdf
- 8. http://www.elinux.org/images/f/fd/MinnowMax_RevA1_sch.pdf
- 9. http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/atom-e3800-family-datasheet.pdf
- 10. https://github.com/adafruit/Adafruit_Python_GPIO
- 11. https://github.com/mjoldfield/Adafruit_Python_GPIO