Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi zero USB Gadget Mode #648

Merged
merged 11 commits into from
Aug 22, 2019
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The _RaspberryMatic_ project is a collaborate effort to provide a lightweight, [
* Latest Linux kernel (RaspberryPi: [4.19.36](https://github.com/raspberrypi/linux/tree/rpi-4.19.y), Tinkerboard: [4.19.40](https://github.com/armbian/build/tree/master/patch/kernel/rockchip-next)) with hard-float (ARMv7) support
* Support to boot system using an external USB memory stick or hard disk (RaspberryPi3 only) or from internal eMMC storage (ASUS Tinkerboard S)
* Supports onboard WiFi of RaspberryPi3, Raspberry Pi Zero W or ASUS Tinkerboard as well as various third-party USB WiFi sticks
* Supports USB Gadget Mode on the Raspberry Pi Zero (after `touch /usr/local/etc/config/gadgetEnabled`)
* Supports onboard Bluetooth of RaspberryPi3, Raspberry Pi Zero W or ASUS Tinkerboard as well as various third-party USB Bluetooth sticks
* Supports [Network UPS Tools](http://networkupstools.org) (NUT) setups including USB connection to uninterruptible power supply (UPS) as well as remote NUT server use (e.g. via Synology NAS Network UPS functionality)
* Support for the following third-party *Hardware Attached on Top* (HAT) boards:
Expand Down
3 changes: 3 additions & 0 deletions buildroot-external/board/raspberrypi0/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dtparam=pwr_led_trigger=timer,act_led_trigger=mmc0
# add device tree overlay for RPI-RF-MOD
dtoverlay=rpi-rf-mod

# enable usb gadget mode for the pi zero
dtoverlay=dwc2

# make sure gpio12 and gpio24 is set as input and pull_up
gpio=12,24=ip,pu

Expand Down
3 changes: 3 additions & 0 deletions buildroot-external/board/raspberrypi0/genimage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ image boot.vfat {
file overlays/pi3-disable-wifi.dtbo {
image = "rpi-firmware/overlays/pi3-disable-wifi.dtbo"
}
file overlays/dwc2.dtbo {
image = "rpi-firmware/overlays/dwc2.dtbo"
}
}
size = 256M
}
Expand Down
1 change: 1 addition & 0 deletions buildroot-external/configs/raspmatic_rpi0_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ BR2_PACKAGE_SSDPD=y
BR2_PACKAGE_EQ3CONFIGD=y
BR2_PACKAGE_NEOSERVER=y
BR2_PACKAGE_JAVA_AZUL=y
BR2_PACKAGE_DTC=y
32 changes: 32 additions & 0 deletions buildroot-external/overlay/base/etc/init.d/S01USBGadget
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
#
# Enable USB Gadget mode
#

case "$1" in
start)
if test -f /usr/local/etc/config/gadgetEnabled; then
printf "Starting usb gadget mode: "
/sbin/modprobe dwc2
/sbin/modprobe g_ether host_addr=00:11:22:33:44:55 dev_addr=00:55:66:77:88:99
echo "OK"
fi
;;
stop)
if test -f /usr/local/etc/config/gadgetEnabled; then
printf "Stopping usb gadget mode: "
/sbin/rmmod g_ether
/sbin/rmmod dwc2
echo "OK"
fi
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit $?
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Rename usb0 to eth0 to make usb gadget ethernet devices work
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",ATTR{address}=="00:55:66:77:88:99",ATTR{dev_id}=="0x0", ATTR{type}=="1",KERNEL=="usb*", NAME="eth0"