dmitrystu / libusb_stm32

Lightweight USB device Stack for STM32 microcontrollers
Apache License 2.0
721 stars 165 forks source link

Device does not enumerate when connected via USB hub on STM32G431 #77

Closed yaqwsx closed 3 years ago

yaqwsx commented 3 years ago

Currently, I am trying to use your awesome library on STM32G431. However, I observe a strange behavior.

I flash your demo program to the MCU. When I connect it directly to my laptop's port, everything works perfectly. However, when I connect it via a USB hub, the device does not enumerate (there are no traces in dmesg) or with some of the USB hubs a trace "Cannot enable. Maybe the USB cable is bad?" appears in the log.

The demo works fine with the same cable and the same USB hubs with STM32F103.

Only the Dp and Dm pins are connected to the STM32G431 MCU. Is possible there is something wrong with the G4 implementation? What can I do to debug the issue? I am wondering if it can have something to do with power-cycling the USB.

EDIT: I am sorry about the empty issue; I misclicked.

dmitrystu commented 3 years ago

Sorry for the late reply. Checked with built-in display hub. See no problems.

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
        |__ Port 3: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 3: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 3: Dev 3, If 2, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 3: Dev 3, If 3, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 4: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 6: Dev 5, If 0, Class=Hub, Driver=hub/3p, 480M
            |__ Port 1: Dev 6, If 0, Class=Hub, Driver=hub/3p, 480M
                |__ Port 1: Dev 7, If 0, Class=Mass Storage, Driver=usb-storage, 480M
                |__ Port 2: Dev 8, If 1, Class=CDC Data, Driver=cdc_acm, 12M
                |__ Port 2: Dev 8, If 2, Class=Human Interface Device, Driver=usbhid, 12M
                |__ Port 2: Dev 8, If 0, Class=Communications, Driver=cdc_acm, 12M
yaqwsx commented 3 years ago

Thank you for your quick response. Based on your comment I tried the demo with Nucleo board, where it worked flawlessly. I examined my board more thoroughly and I found the problem - there are also resistors on the data lines to implement a QuickCharge device. They were wired differently compared to my board with STM32F103 (by mistake). Removing those resistors solved the issue - the hub is probably more sensitive compared to the laptop for weir voltage levels on the data lines.