Posts: 1
Joined: Wed May 15, 2019 6:26 am

write() call to usb gadget device hangs

Wed May 15, 2019 6:33 am

I'm following the instructions here for a HID device on a Raspberry Pi Zero W. Everything seems to go well, I'm able to create the USB gadget on the Pi and all the files have the correct info. When I try to run a simple `write()` call to `/dev/hidg0`, it never terminates. For instance, `strace echo -ne "\0" > /dev/hidg0` stops at `write(1, "\0", 1` and never finishes.

I'm using a freshly installed kernel + Raspbian Lite image, my config files are below. Any ideas?

Code: Select all

[email protected] ~> cat /etc/modules

[email protected] ~> cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=9b12917d-02 rootfstype=ext4 elevator=deadline rootwait modules-load=dwc2

[email protected] ~> cat /boot/config.txt  | tail -n 10

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)


Posts: 1
Joined: Sun Jun 02, 2019 4:51 pm

Re: write() call to usb gadget device hangs

Sun Jun 02, 2019 5:12 pm

I was running into the same problem last night.

For you (assuming you did everything correctly in the tutorial like set up the script correctly with the appropriate functions in /usr/bin/isticktoit_usb, made it executable, put "/usr/bin/isticktoit_usb" in rc.local, and then restarted the pi), it looks like you may be missing the "dwc2" in your /etc/modules file.

For me, the micro usb to usb cord I was using did not have a data transfer line. As a result, the pi couldn't send anything, so it just hung. Make sure that the other device you are connecting to is able to make a connection and then identify your pi as a keyboard before you try to write anything, otherwise it may hang.

Also, some information online may say that you need to downgrade your kernel and os since some versions seem to not work, but I was able to successfully write from my Raspberry Pi Zero W V1.1 with Raspian Stretch Lite Version: April 2019, Release Date: 2019-04-08, and Kernel 4.14.98+.

Return to “Advanced users”