GadgetFS: disconnect from host


in my project my SOM is connected as a usb device with gadgetfs to a Windows PC. The enumeration and communication works fine.

Now I want to disconnect the SOM from the host by firmware (cable is still connected). For this I clear the content of /sys/kernel/config/usb_gadget/g1/UDC and close all endpoints of the gadget.

Unfortunately Windows doesn’t recognize that the device isn’t present anymore and still lists it in the device manager.

What else do I have to do? Clamp the USB data lines to ground? Modify any bits in the registers of the USB controller? Or must the Device tree be changed?

Best regards,

Hi @Mowlwurf

I would expect that what you do is enough. What happens if you unplug and re-plug the cable after the unbind? Does Windows again enumerate it? Or does the device just not properly do a disconnect? I could imagine that in your case the device just does nothing and Windows doesn’t probe. Therefore, Windows still thinks the device is there. Does it maybe work if you load the gadget driver as module and just unload the module with rmmod?


When I unbind the device by clearing the content of /sys/kernel/config/usb_gadget/g1/UDC nothing happens in Windows.

When I unplug and replug the cable Windows doesn’t re-enumerate the device.

So I would see it the same way as you: the device doesn’t disconnect at all and Windows thinks that the device is still present.

I’m not sure what you mean with ‘gadget driver’. The gadgetfs?

Hi @Mowlwurf

I assume you build CONFIG_USB_F_MASS_STORAGE is that correct? If you build this driver as module you can unload it by just doing a:

rmmod usb_f_mass_storage

This unloads (not unbinds) the driver. If you want to load it again you do a:

modprobe usb_f_mass_storage


I’m sorry, I mixed up gadgetfs and configfs.

I’m using CONFIG_USB_CONFIGFS=m like the reference image with CONFIG_USB_CONFIGFS_F_FS=y . In my application I start a gadget with the libusbgx and I want to disconnect it with usbg_disable_gadget (it’s like echo “” > /sys/kernel/config/usb_gadget/g1/UDC).

But this won’t work …

So for configfs I have to build the kernel with CONFIG_USB_CONFIGFS_F_FS=m and unload the driver with

rmmod usb_f_fs


I was able unload the kernel module for usb_f_fs but the device is still present in the Windows device manager.

Hi @Mowlwurf

Hmm, this is strange… I tested with a Linux PC and it seems to recognize that the device disappears. Have you tried to use some cleanup function from libusbx to get it removed? Maybe it’s also a problem of Windows which just expects a device only changes when it properly disconnects from the host. Then disconnecting the lanes would be the only solution I guess.


When I close my application the gadget is removed completly from the system using the libusbgx-API. Nevertheless the device is still present in the device manager.

When I restart the application and the gadget is intialised than the enumeration process of Windows restarts.

I agree with you that this behavior seems to be Windows depended and the D+/- lanes needs to be disconnected by hardware.

Thank you for your help

Perfect, thanks for the feedback!