1

I am currently working on a Raspberry Pi project, and found an amazing feature that I used many times on my LineageOs phone: Usb Gadget.

I figured I could change the function of the Usb port to act as another one, using the RPi Zero as well. However, a project I am undergoing requires it to act as both a usb gadget (Ethernet-over-USB) and a usb host (To mount a usb drive for example).

Now, I do realize that the RPi does only have one usb port (OTG), so I was wondering if by any chance, it was possible, with the means of a usb hub, to make the RPi use both functions. Maybe not all usb hubs support the feature?

I did a bit of research and I thought of an idea. So far, I have managed to make both functions work, but not simultaneously (Couldn't enable the gadget through the usb hub). It would be better if they worked simultaneously, but it's alright if at least, I can connect a usb drive, the RPi as a host, and connect the RPi to my pc right after (without a reboot or an access to the shell).

Maybe, the RPi could: when a device gets connected, before doing anything, check what is the connected device; If it is my pc, load the driver with configFs/GadgetFs, and create a usb gadget. If it is a usb device (such as a Usb drive), then leaves it as it is.

Edit: Ask me if you need to know anything else, too.

1 Answer 1

2

Maybe not all usb hubs support the feature?

None of the hubs support this feature. Hubs only have one upstream port, and it's impossible for the same hub port to be both upstream and downstream.

Maybe, the RPi could: when a device gets connected, before doing anything, check what is the connected device

This should technically be possible (at least the Raspbian kernel is built with CONFIG_USB_DWC2_DUAL_ROLE=y), though I have no idea how reliably you can get it to work. I don't have a Pi Zero, but I'd try loading a USB gadget driver such as g_mass_storage and then check if /sys/class/udc/<ID>/state changes as you connect the Pi to a USB host or a USB device.

Your Answer

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

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