From 4102628a3b79b54333e64b68ca233684470553ab Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 3 Apr 2023 21:03:07 +0800 Subject: [PATCH 1/3] Fix usb enumeration stage error for some device --- components/usb/hub.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/usb/hub.c b/components/usb/hub.c index da53cae2b62c..4606e4486380 100644 --- a/components/usb/hub.c +++ b/components/usb/hub.c @@ -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 { @@ -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; @@ -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; From 71786a7413c43d0b0103b4174da3b4905a1f6e7a Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Mon, 17 Apr 2023 17:06:54 +0800 Subject: [PATCH 2/3] usb_host: Update docs and comments regarding first configuration enumeration This commit updates some comments and documentation regarding changes made in PR https://github.com/espressif/esp-idf/pull/11113. --- components/usb/hub.c | 2 +- docs/en/api-reference/peripherals/usb_host.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/usb/hub.c b/components/usb/hub.c index 4606e4486380..148c4820f7d2 100644 --- a/components/usb/hub.c +++ b/components/usb/hub.c @@ -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 diff --git a/docs/en/api-reference/peripherals/usb_host.rst b/docs/en/api-reference/peripherals/usb_host.rst index f3966550e295..c4a10d462186 100644 --- a/docs/en/api-reference/peripherals/usb_host.rst +++ b/docs/en/api-reference/peripherals/usb_host.rst @@ -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. From f1a2bc777ebbac23a20e169b3a1db019959ff344 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Wed, 19 Apr 2023 11:06:25 +0200 Subject: [PATCH 3/3] usb_host: Use up-to-date syntax in pytest --- components/usb/test_apps/hcd/pytest_usb_hcd.py | 6 ++---- components/usb/test_apps/usb_host/pytest_usb_host.py | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/components/usb/test_apps/hcd/pytest_usb_hcd.py b/components/usb/test_apps/hcd/pytest_usb_hcd.py index f82af201a08b..d91f79b14e24 100644 --- a/components/usb/test_apps/hcd/pytest_usb_hcd.py +++ b/components/usb/test_apps/hcd/pytest_usb_hcd.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest @@ -9,6 +9,4 @@ @pytest.mark.esp32s3 @pytest.mark.usb_host_flash_disk def test_usb_hcd(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[full_speed]') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(group='full_speed') diff --git a/components/usb/test_apps/usb_host/pytest_usb_host.py b/components/usb/test_apps/usb_host/pytest_usb_host.py index f7de504e14c0..7a6a5740c7e1 100644 --- a/components/usb/test_apps/usb_host/pytest_usb_host.py +++ b/components/usb/test_apps/usb_host/pytest_usb_host.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest @@ -9,6 +9,4 @@ @pytest.mark.esp32s3 @pytest.mark.usb_host_flash_disk def test_usb_host(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[full_speed]') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(group='full_speed')