Systemd unit for managing USB gadgetsFri 19 October 2018 by Lars Kellogg-Stedman Tags raspberrypi usb
The Pi Zero (and Zero W) have support for acting as a USB gadget: that means that they can be configured to act as a USB device -- like a serial port, an ethernet interface, a mass storage device, etc.
There are two different ways of configuring this support. The first only allows you to configure a single type of gadget at a time, and boils down to:
- Enable the dwc2 overlay in
This process is more fully documented here.
The second mechanism makes use of the
libcomposite driver to create
multifunction gadgets. The manual procedure is documented in the
kernel documentation. While it's a useful feature, the
configuration process requires several steps and if you only do it
infrequently it can be easy to forget.
In order to make this easier for me to manage, I've wrapped the process up in a systemd template unit that takes care of the various steps necessary to both create and remove a multifunction USB gadget.
Once installed, creating a gadget that offers both a serial interface and a network interface is as simple as:
Create a file
systemctl start usb-gadget@g0.
You can remove the gadget by running
systemctl stop usb-gadget@g0.
As with any systemd service, you can mark the unit to start
automatically when your system boots by running
The systemd-usb-gadget project can be found at:
Configuring a static address for wlan0 on Raspbian Stretch
Recent releases of Raspbian have adopted the use of dhcpcd to
manage both dynamic and static interface configuration. If you would
prefer to use the traditional
instead, follow these steps.
systemctl disable --now dhdpcd wpa_supplicant
You will need a
Some notes on PWM on the Raspberry Pi
Systemd-nspawn for fun and...well, mostly for fun
systemd-nspawn has been called "chroot on steroids",
but if you think of it as Docker with a slightly different target
you wouldn't be far wrong, either. It can be used to spawn containers
on your host, and has a variety of options for configuring the
containerized environment through the use …