Hello everyone,
I want to use Raspberry Pi 4B or 5 as a USB proxy for a USBHID device. As the first step, I'm trying to connect a Raspberry Pi 4B to my MacBook M1 using a USB-C to USB-C cable. The power is provided from GPIO and I use the documentation in https://pip-assets.raspberrypi.com/cate ... 20SBCs.pdf. In the /boot/config.txt, this line is added:and for testing the gadget mode functionality, I'm trying to first connect it in gadget mode. For this, I have tested 2 methods. For the first method (old deprecated module), I have added this to crontab:And for the second method, this script is run using systemctl:In both cases, I connect the Pi after it's booted up and expect to either see a new device using this command on host:which remains the same and does not show a new device, or an updated state in this file of the Pi:which remains "not attached" after connecting.
I hope this explanation is complete enough to show all the steps I have done. Please tell me to add any more required information if it's missing here.
I want to use Raspberry Pi 4B or 5 as a USB proxy for a USBHID device. As the first step, I'm trying to connect a Raspberry Pi 4B to my MacBook M1 using a USB-C to USB-C cable. The power is provided from GPIO and I use the documentation in https://pip-assets.raspberrypi.com/cate ... 20SBCs.pdf. In the /boot/config.txt, this line is added:
Code:
dtoverlay=dwc2,dr_mode=peripheralCode:
@reboot /sbin/modprobe g_mass_storage file=/home/pouya/drive.binCode:
#!/usr/bin/env bashset -euo pipefailsudo modprobe libcompositecd /sys/kernel/config/usb_gadget# Create our new gadgetsudo mkdir MyGadget || truecd MyGadget# Add some boilerplate data that the gadget needsecho 0x1d6b > idVendor # Linux Foundation’s USB VID. Replace with your own VID if requiredecho 0x0104 > idProduct # Multifunction Composite Gadgetecho 0x0100 > bcdDevice # v1.0.0echo 0x0200 > bcdUSB # USB2mkdir strings/0x409 || true # 0x409 = English# Insert your own manufacturer and gadget name hereecho "RaspberryPi" > strings/0x409/manufacturerecho "MyPiGadget" > strings/0x409/product# Make the serial number the same as the Raspberry Pi serial number; you can use whatever is required hereSERIAL=`cat /proc/cpuinfo | awk '/Serial/ {print $3}' `echo $SERIAL > strings/0x409/serialnumber# Create a configuration area and populatemkdir configs/c.1 || trueecho 120 > configs/c.1/MaxPowermkdir configs/c.1/strings/0x409 || trueecho "Config 1" > configs/c.1/strings/0x409/configuration# Create our specific gadget type — this example is a mass storage device, but you can make various different typesmkdir functions/mass_storage.usb0 || true# Set up our backing storeecho "/home/pouya/drive.bin" > functions/mass_storage.usb0/lun.0/file# Link our function to our configurationln -s functions/mass_storage.usb0 configs/c.1/UDC=`ls /sys/class/udc`echo $UDC > UDCCode:
ioreg -p IOUSBCode:
/sys/class/udc/fe980000.usb/stateI hope this explanation is complete enough to show all the steps I have done. Please tell me to add any more required information if it's missing here.
Statistics: Posted by pouyae — Wed Oct 15, 2025 8:30 pm — Replies 0 — Views 29