2

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?

4
  • Changing the OS is unlikely to make a difference, although if you are following outdated directions that might. WRT "raspbian-stretch" "raspbian-4.4.y": Raspbian is the distribution name, and stretch is the specific release (aka. version 9) of that distro, but 4.4.y is a linux kernel version. I.e., there is no such thing as "Raspbian-4.4.y". You could be using kernel 4.4.y with Raspbian stretch.
    – goldilocks
    Dec 6, 2018 at 15:17
  • 1
    "I then plugged the RPi Zero into my Fedora 29 laptop" -> That implies you rebooted it, i.e., it was powered on by plugging it into the laptop. If so, the script you ran previously doesn't accomplish anything -- /sys (including kernel/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.
    – goldilocks
    Dec 6, 2018 at 15:23
  • Finally, apt update just updates the local repository database. It doesn't update any of the software. For that you would subsequently call apt upgrade.
    – goldilocks
    Dec 6, 2018 at 17:48
  • Please feel free to tick the "accept" sign to mark your answer as correct and the question as solved. Thanks. (See the tour).
    – Ghanima
    Dec 7, 2018 at 18:37

1 Answer 1

0

Found the problem. I wasn't using a OTG cable. Incredible!

2
  • Can you please accept your answer to show others that it is solved?
    – Ingo
    Dec 15, 2018 at 11:31
  • I don't quite understand: if your laptop is upstream and the Pi is downstream, wouldn't you need a regular cable, not the OTG one? How did you even plug an OTG cable in a laptop? Feb 14, 2022 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.