-
Notifications
You must be signed in to change notification settings - Fork 22
Home
The goal of this project is to produce software that allows a Raspberry Pi Zero to be connected as USB accessory to a computer running Pixel. The GPIO pins of the Pi Zero will then be made available to the host computer, for use by applications using the pigpio library.
This is achieved by emulating an USB Ethernet dongle, and running the pigpiod
daemon on the Pi Zero
Building the software is done on a regular computer running Linux.
First the build dependencies need to be installed.
- If the Linux distribution used is Debian or Ubuntu this can be done with the command:
sudo apt-get update
sudo apt-get install git-core build-essential rsync libncurses-dev unzip python bc
- Then download the build scripts from this repository:
git clone --depth 1 https://github.com/raspberrypi/gpioexpander.git
- Start the build process with:
cd gpioexpander
./build.sh
The first time the build.sh
script is run, it will first build the toolchain (compiler, etc.) used to cross-compile for the target system, before it proceeds to build the image itself.
Be aware that this can take a long time to complete.
After the build is complete the resulting files will be in the “output” directory.
The files can be booted on a Pi Zero by connecting it to your computer with a USB cable and using the rpiboot utility (provided it is installed, see https://github.com/raspberrypi/usbboot for instructions)
sudo ./rpiboot -d output
Or you can use the GUI available at: https://github.com/raspberrypi/usbbootgui
The host computer can connect to the pigpio daemon running on the Pi zero by using the address fe80::1%usb0
This address can either be specified in the source code of the application using pigpio, or by setting a PIGPIO_ADDR environment variable.
When using usbbootgui
on the Intel platform, this variable is set automatically.
|-- buildroot-2017.02.tar.gz
|-- build.sh
|-- gpioexpand
| |-- board
| | |-- kernelconfig-gpioexpand.fragment
| | |-- kernelconfig-recovery.armv6
| | `-- overlay
| | `-- etc
| | `-- init.d
| | `-- S99gpioext
| |-- Config.in
| |-- configs
| | `-- gpioexpand_defconfig
| |-- external.desc
| |-- external.mk
| `-- package
| |-- pigpio
| | |-- Config.in
| | `-- pigpio.mk
| `-- rpi-firmware-custom
| |-- Config.in
| `-- rpi-firmware-custom.mk
|-- output
| |-- cmdline.txt
| |-- config.txt
| `-- LICENSE
`-- README.md
Buildroot 2017.02 is used as build environment. With buildroot it is possible to modify the build scripts within the buildroot folder itself to suit your needs, which is easiest. Or it is possible to store customizations in a separate external directory. This is slightly more difficult to setup but comes with the advantage that the modifications are clearly separate from the original buildroot files. Making it easier for third-party developers to see what files were changed, and making upgrades to a later Buildroot edition more trivial.
This project uses the last method.
The original buildroot files are inside buildroot-2017.02.tar.gz
which is extracted to the buildroot-2017.02
folder upon first use of build.sh
Our own configuration files are inside the gpioexpand
directory.
The buildroot configuration describing things like which software packages are enabled is stored in gpioexpand/configs/kernelconfig-gpioexpand.fragment
A minimal kernel configuration (copied from the NOOBS project) is available in gpioexpand/board/kernelconfig-recovery.armv6
The extra kernel options we want to have on top of the minimal kernel -such as USB gadget support are in gpioexpand/board/kernelconfig-gpioexpand.fragment
The advantage of having separate files for the minimal kernel configuration and the extra options is that it simplifies upgrading to a newer kernel version.
The files Config.in
, external.mk
, and package/*
concern extra packages.
In our case we have two custom packages:
rpi-firmware-custom
This is actually just a copy of the rpi-firmware
package that is bundled with buildroot itself, except that we modified it to download a later version of the Raspberry Pi boot firmware files (for USB boot functionality).
pigpio
This package builds the pigpiod
daemon.
The main functionality is in the file gpioexpand/board/overlay/etc/init.d/S99gpioext
This is a sysv style start-up script that is responsible for:
- Creating the USB composite device
- Setting up networking
- Starting the
pigpiod
daemon
An USB composite device is created, and configured by the startup script through configfs. Composite devices allow multiple USB device classes to be offered to the host simultaneously.
In the current implementation an (ECM device class) Ethernet device is offered to facilitate TCP/IP communication with pigpiod
.
In addition an (ACM device class) serial device is made available as serial console for debugging purposes. One can connect to the latter on the host system by executing screen /dev/ttyACM0 115200
But it would also be relatively easy to extend this in the future to expose more functionality, if there is any demand for it. E.g. the SD card could be exposed by enabling Mass Storage Device class support through configfs. Or CSI could be exposed by offering UVC (webcam) device class support.
A fixed IPv6 link local address of fe80::1
is configured on the Pi Zero.
The advantage of using link local addresses is that they are specific to a single network link, and you can have the same address on multiple links without risk of conflicts.
On the host computer a "scope identifier" need to be specified to indicate on which link to connect.
E.g. to connect to the Pi Zero you normally use the address fe80::1%usb0
If there is more than one, the second one will be assigned usb1
instead, and you can connect to it by using fe80::1%usb1
etc.
More information about the buildroot infrastructure (that does most of the hard work) can be found at:
https://buildroot.org/downloads/manual/manual.html
http://free-electrons.com/doc/training/buildroot/buildroot-slides.pdf