HOWTO: Enable USB device mode on Pi Zero
Posted: Mon Dec 21, 2015 2:29 pm
Firstly, many thanks to ED6E0F17, notro and others on github who worked this all out. The original thread is here. I am Dave-0 in that thread but I didn't do the clever bits.
This is very new and a bit rough and ready so please chip in with corrections and improvements. Any mistakes are most likely to be mine.
To enable USB device mode (also referred to as peripheral mode or gadget mode) on a Pi Zero follow the steps below. If you are using device mode you can't plug in a keyboard or mouse to control the Pi. Because of this, I advise using a 3.3v USB-serial adapter connected to the 40 pin header when trying this out, that way you can get a shell. The following steps assume you are using a Linux host system and that you are modifying a Raspbian install. I won't be going into detail on compiling kernels as that's already documented here.
1. Download the 4.4.y branch of the Pi kernel.
You get this from github:
2. Modify the bcm2708_common.dtsi file.
You can do this either my applying this patch or by editing arch/arm/boot/dts/bcm2708_common.dtsi and changing the section that reads:
to read:
3. Change the kernel config.
Start with the default configuration (bcmrpi_defconfig) and make the following changes in menuconfig:
4. Compile and install
Compile and install your new kernel, bcm2708-rpi-b.dtb and modules on to your Raspbian card. Take a backup first unless you're not bothered about losing anything if it goes wrong. You will also need to replace the standard config.txt with this one:
5.Boot and try it out.
Boot your modified Raspbian install. If you've connected a USB serial adapter as suggested, connect this first and start a session:
(It might be something other than /dev/ttyUSB0 depending on the hardware.)
When Raspbian boots you should get something like this on the host:
dmesg:
lsusb:
Log into the PI using via the screen session that you started earlier. To enable a login session using the new USB serial gadget (device mode), do this:
You should be able to start another screen session via the new USB gadget device:
This is a persistent change so you should now be able to login without the USB serial adapter and nothing connected to the PI other than a normal USB cable.
Enjoy!
This is very new and a bit rough and ready so please chip in with corrections and improvements. Any mistakes are most likely to be mine.

To enable USB device mode (also referred to as peripheral mode or gadget mode) on a Pi Zero follow the steps below. If you are using device mode you can't plug in a keyboard or mouse to control the Pi. Because of this, I advise using a 3.3v USB-serial adapter connected to the 40 pin header when trying this out, that way you can get a shell. The following steps assume you are using a Linux host system and that you are modifying a Raspbian install. I won't be going into detail on compiling kernels as that's already documented here.
1. Download the 4.4.y branch of the Pi kernel.
You get this from github:
Code: Select all
git clone --depth=1 --branch=rpi-4.4.y https://github.com/raspberrypi/linux
You can do this either my applying this patch or by editing arch/arm/boot/dts/bcm2708_common.dtsi and changing the section that reads:
Code: Select all
usb: usb@7e980000 {
compatible = "brcm,bcm2708-usb";
reg = <0x7e980000 0x10000>,
<0x7e006000 0x1000>;
interrupts = <2 0>,
<1 9>;
Code: Select all
compatible = "brcm,bcm2835-usb";
reg = <0x7e980000 0x10000>;
interrupts = <1 9>;
g-np-tx-fifo-size = <32>;
g-rx-fifo-size = <256>;
g-tx-fifo-size = <256 128 128 64 64 64 32>;
Start with the default configuration (bcmrpi_defconfig) and make the following changes in menuconfig:
- Go to Device drivers -> USB support
- Deselect "Synopsis DWC host support"
- Select "USB Gadget Support" as built-in
- Enter the "USB Gadget Support" section
- Select "USB Gadget Drivers" as built in
- In that section, select the gadget type that you want, I'll use "Serial Gadget (with CDC ACM and CDC OBEX support)" here*
- Go back up a level
- Select "DesignWare USB2 DRD Core Support" as built in
- Select "DWC2 Mode Selection (Dual Role mode)" and choose "Gadget only mode" [EDIT: or not, dual mode works]
- Save and exit.
4. Compile and install
Compile and install your new kernel, bcm2708-rpi-b.dtb and modules on to your Raspbian card. Take a backup first unless you're not bothered about losing anything if it goes wrong. You will also need to replace the standard config.txt with this one:
Code: Select all
device_tree=bcm2708-rpi-b.dtb
Boot your modified Raspbian install. If you've connected a USB serial adapter as suggested, connect this first and start a session:
Code: Select all
screen /dev/ttyUSB0 115200,N,8,1
When Raspbian boots you should get something like this on the host:
dmesg:
Code: Select all
[ 7330.929356] usb 2-3.2: new high-speed USB device number 35 using ehci-pci
[ 7331.031354] usb 2-3.2: New USB device found, idVendor=0525, idProduct=a4a7
[ 7331.031366] usb 2-3.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 7331.031373] usb 2-3.2: Product: Gadget Serial v2.4
[ 7331.031378] usb 2-3.2: Manufacturer: Linux 4.4.0-rc5+ with 20980000.usb
[ 7331.039935] cdc_acm 2-3.2:2.0: This device cannot do calls on its own. It is not a modem.
[ 7331.040093] cdc_acm 2-3.2:2.0: ttyACM0: USB ACM device
Code: Select all
Bus 002 Device 035: ID 0525:a4a7 Netchip Technology, Inc. Linux-USB Serial Gadget (CDC ACM mode)
Code: Select all
systemctl enable getty@ttyGS0.service
Code: Select all
screen /dev/ttyACM0 115200,N,8,1
Enjoy!