I'm using a RPi Zero W for this exercise. I downloaded 2018-11-13-raspbian-stretch-full.zip and installed it onto a 32G microSD card:
sudo dd bs=4M if=2018-11-13-raspbian-stretch-full.img of=/dev/mmcblk0
Booted my RPi Zero W using the aforementioned microSD card and immediately update the system:
apt-get update
Added the following two lines at the end of /etc/modules:
dwc2
libcomposite
Then executed the following shell script:
#!/bin/sh
# Create gadget
mkdir /sys/kernel/config/usb_gadget/mykeyboard
cd /sys/kernel/config/usb_gadget/mykeyboard
# Add basic information
echo 0x0100 > bcdDevice # Version 1.0.0
echo 0x0200 > bcdUSB # USB 2.0
echo 0x00 > bDeviceClass
echo 0x00 > bDeviceProtocol
echo 0x00 > bDeviceSubClass
echo 0x08 > bMaxPacketSize0
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x1d6b > idVendor # Linux Foundation
# Create English locale
mkdir strings/0x409
echo "My manufacturer" > strings/0x409/manufacturer
echo "My virtual keyboard" > strings/0x409/product
echo "0123456789" > strings/0x409/serialnumber
# Create HID function
mkdir functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 8 > functions/hid.usb0/report_length # 8-byte reports
echo 1 > functions/hid.usb0/subclass
# Write report descriptor
echo "05010906a101050719e029e71500250175019508810275089501810175019503050819012903910275019505910175089506150026ff00050719002aff008100c0" | xxd -r -ps > functions/hid.usb0/report_desc
# Create configuration
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo 0x80 > configs/c.1/bmAttributes
echo 200 > configs/c.1/MaxPower # 200 mA
echo "Example configuration" > configs/c.1/strings/0x409/configuration
# Link HID function to configuration
ln -s functions/hid.usb0 configs/c.1
# Enable gadget
ls /sys/class/udc > UDC
I then plugged the RPi Zero into my Fedora 29 laptop expecting to see the RPi show up when I executed: lsusb -t with the device (my RPi Zero) showing up with Class=Human Interface Device.
Nothing shows up, except my known devices.
I know this is an exercise in ConfigFS and how to use it to turn your micro-micro-micro Linus board into a "USB gadget".
Is raspbian-stretch the correct OS for this purpose?
Maybe raspbian-4.4.y ?
git clone --depth=1 --branch=rpi-4.4.y https://github.com/raspberrypi/linux
Any suggestions?
/sys
(includingkernel/config
) is an in-memory only virtual filesystem used as a kernel interface while the system is running. It does not exist on the SD card or anywhere else and is created by the kernel at each boot. If you try to write something with that path to the SD card by putting it in another machine, etc. it will be meaningless.apt update
just updates the local repository database. It doesn't update any of the software. For that you would subsequently callapt upgrade
.