Skip to content

Commit

Permalink
Merge branch 'contrib/github_pr_11113' into 'master'
Browse files Browse the repository at this point in the history
Fix usb enumeration stage error for some device (GitHub PR)

Closes IDFGH-9778

See merge request espressif/esp-idf!23233
  • Loading branch information
Dazza0 committed Apr 18, 2023
2 parents c898321 + 525de5b commit f93bb3a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions components/usb/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ implement the bare minimum to control the root HCD port.

#define ENUM_CTRL_TRANSFER_MAX_DATA_LEN CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE
#define ENUM_DEV_ADDR 1 //Device address used in enumeration
#define ENUM_CONFIG_INDEX 0 //Index of the first configuration of the device
#define ENUM_CONFIG_INDEX 0 //Index used to get the first configuration descriptor of the device
#define ENUM_SHORT_DESC_REQ_LEN 8 //Number of bytes to request when getting a short descriptor (just enough to get bMaxPacketSize0 or wTotalLength)
#define ENUM_WORST_CASE_MPS_LS 8 //The worst case MPS of EP0 for a LS device
#define ENUM_WORST_CASE_MPS_FS 64 //The worst case MPS of EP0 for a FS device
Expand Down Expand Up @@ -164,6 +164,7 @@ typedef struct {
uint8_t iProduct; /**< Index of the Product string descriptor */
uint8_t iSerialNumber; /**< Index of the Serial Number string descriptor */
uint8_t str_desc_bLength; /**< Saved bLength from getting a short string descriptor */
uint8_t bConfigurationValue; /**< Device's current configuration number */
} enum_ctrl_t;

typedef struct {
Expand Down Expand Up @@ -365,7 +366,7 @@ static bool enum_stage_transfer(enum_ctrl_t *enum_ctrl)
break;
}
case ENUM_STAGE_SET_CONFIG: {
USB_SETUP_PACKET_INIT_SET_CONFIG((usb_setup_packet_t *)transfer->data_buffer, ENUM_CONFIG_INDEX + 1);
USB_SETUP_PACKET_INIT_SET_CONFIG((usb_setup_packet_t *)transfer->data_buffer, enum_ctrl->bConfigurationValue);
transfer->num_bytes = sizeof(usb_setup_packet_t); //No data stage
enum_ctrl->expect_num_bytes = 0; //OUT transfer. No need to check number of bytes returned
break;
Expand Down Expand Up @@ -516,6 +517,7 @@ static bool enum_stage_transfer_check(enum_ctrl_t *enum_ctrl)
case ENUM_STAGE_CHECK_FULL_CONFIG_DESC: {
//Fill configuration descriptor into the device object
const usb_config_desc_t *config_desc = (usb_config_desc_t *)(transfer->data_buffer + sizeof(usb_setup_packet_t));
enum_ctrl->bConfigurationValue = config_desc->bConfigurationValue;
ESP_ERROR_CHECK(usbh_hub_enum_fill_config_desc(enum_ctrl->dev_hdl, config_desc));
ret = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion docs/en/api-reference/peripherals/usb_host.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Therefore, in addition to the client tasks, the Host Library also requires a tas
Devices
^^^^^^^

The Host Library hides the details of device handling (such as connection, memory allocation, and enumeration) from the clients. The clients are provided only with a list of already connected and enumerated devices to choose from. During enumeration, each device is configured to use configuration 1.
The Host Library hides the details of device handling (such as connection, memory allocation, and enumeration) from the clients. The clients are provided only with a list of already connected and enumerated devices to choose from. During enumeration, each device is automatically configured to use the first configuration found (i.e., the first configuration descriptor returned on a Get Configuration Descriptor request). For most standard devices, the first configuration will have a ``bConfigurationValue`` of ``1``.

It is possible for a two or more clients to simultaneously communicate with the same device as long as they are not communicating to the same interface. However, multiple clients can simultaneously communicate with the same device's default endpoint (EP0), which will result in their control transfers being serialized.

Expand Down

0 comments on commit f93bb3a

Please sign in to comment.