cancel
Showing results for 
Search instead for 
Did you mean: 

USB Host with Hal libraries - enumeration problem

VCapu
Associate III

Hello. I'm using a custom board with STM32F105RBT6. I used the MX_USB_HOST_Init() funtion to configure the host usb in mode usb_otg_fs. The problem is that some USB keys don't work (the USBH_Process() function can't go further the HOST_ENUMERATION state).

Checking all the value returned by the involved functions I see this:

USBH_HandleEnum() returns USBH_BUSY (in the ENUM_IDLE state);

USBH_Get_DevDesc() returns USBH_BUSY;

USBH_GetDescriptor() returns USBH_BUSY;

USBH_CtlReq(phost, buff, length) returns USBH_BUSY;

Inside the USBH_CtlReq() function, after the CMD_SEND, the functions goes to the CMD_WAIT state and the USBH_HandleControl() function returns USBH_BUSY.

The USBH_HandleControl() is in the state CTRL_SETUP_WAIT, where the USBH_LL_GetURBState() function returns sometimes USBH_URB_IDLE or

 USBH_URB_NOTREADY or USBH_URB_ERROR.

What could be the reason?

2 REPLIES 2
Robmar
Senior III

I have the exact same issue interfacing to the CP2102, has anyone solved this?

NZSmartie
Associate

I'm currently having the same problem when enumerating a CH340 chip.

I don't have many examples to go off of, but it appears that Windows doesn't ask for just the Configuration Descriptor of 9 bytes, but requested 47 bytes (in wLength). The CH340 responded with only 39 bytes of data (1 config, 1 interface and 3 endpoint descriptors). So I'm wondering if this is a bug with the CH340 and similar chips that do not respond to a Config Descriptor Request with a length of 9 (which is big enough for just the config descriptor)

My work around is to directly interfere with the EnumState by skipping ENUM_GET_CFG_DESC and going to ENUM_GET_FULL_CFG_DESC with a oversized wTotalLength set. 

if (husbh.EnumState == ENUM_GET_CFG_DESC) {
    husbh.device.CfgDesc.wTotalLength = 47;
    husbh.EnumState = ENUM_GET_FULL_CFG_DESC;
}
USBH_Process(&husbh);

 Not ideal, but it does allow my custom vendor class to be requested at least.