diff --git a/components/usb/test_apps/.build-test-rules.yml b/components/usb/test_apps/.build-test-rules.yml index 9406f23a66..c8b66b72e6 100644 --- a/components/usb/test_apps/.build-test-rules.yml +++ b/components/usb/test_apps/.build-test-rules.yml @@ -4,7 +4,7 @@ components/usb/test_apps: enable: - if: SOC_USB_OTG_SUPPORTED == 1 disable_test: - - if: IDF_TARGET not in ["esp32s3"] + - if: IDF_TARGET not in ["esp32s3", "esp32p4"] temporary: true reason: lack of runners with usb_host_flash_disk tag depends_components: diff --git a/components/usb/test_apps/common/test_usb_mock_msc.c b/components/usb/test_apps/common/test_usb_mock_msc.c index db61ec10b7..6f75260236 100644 --- a/components/usb/test_apps/common/test_usb_mock_msc.c +++ b/components/usb/test_apps/common/test_usb_mock_msc.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -60,22 +60,42 @@ uint8_t mock_msc_scsi_config_desc[255]; uint16_t mock_msc_scsi_str_desc_manu[128]; uint16_t mock_msc_scsi_str_desc_prod[128]; uint16_t mock_msc_scsi_str_desc_ser_num[128]; +usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc; +usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc; -const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc = { +const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc_fs = { .bLength = sizeof(usb_ep_desc_t), .bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT, .bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR, //EP 1 OUT .bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK, - .wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS, //MPS of 64 bytes + .wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_FS, //MPS of 64 bytes .bInterval = 0, }; -const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc = { +const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc_hs = { + .bLength = sizeof(usb_ep_desc_t), + .bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT, + .bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR, //EP 1 OUT + .bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK, + .wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_HS, //MPS of 512 bytes + .bInterval = 0, +}; + +const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc_fs = { .bLength = sizeof(usb_ep_desc_t), .bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT, .bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR, .bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK, - .wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS, //MPS of 64 bytes + .wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_FS, //MPS of 64 bytes + .bInterval = 0, +}; + +const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc_hs = { + .bLength = sizeof(usb_ep_desc_t), + .bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT, + .bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR, + .bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK, + .wMaxPacketSize = MOCK_MSC_SCSI_BULK_EP_MPS_HS, //MPS of 512 bytes .bInterval = 0, }; @@ -130,9 +150,10 @@ void mock_msc_scsi_init_reference_descriptors(void) dest_ptr += USB_CONFIG_DESC_SIZE; memcpy(dest_ptr, (void*)&mock_msc_intf_desc, sizeof(mock_msc_intf_desc)); dest_ptr += USB_INTF_DESC_SIZE; - memcpy(dest_ptr, (void*)&mock_msc_scsi_bulk_in_ep_desc, sizeof(mock_msc_scsi_bulk_in_ep_desc)); + // Set endpoint descriptors with zeroes, FS or HS device has not been connected + memset(dest_ptr, 0, sizeof(usb_ep_desc_t)); dest_ptr += USB_EP_DESC_SIZE; - memcpy(dest_ptr, (void*)&mock_msc_scsi_bulk_out_ep_desc, sizeof(mock_msc_scsi_bulk_out_ep_desc)); + memset(dest_ptr, 0, sizeof(usb_ep_desc_t)); // String descriptors const char *str = MOCK_MSC_SCSI_STRING_1; diff --git a/components/usb/test_apps/common/test_usb_mock_msc.h b/components/usb/test_apps/common/test_usb_mock_msc.h index accd78e82e..466decf2be 100644 --- a/components/usb/test_apps/common/test_usb_mock_msc.h +++ b/components/usb/test_apps/common/test_usb_mock_msc.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -63,7 +63,7 @@ bLength : 0x07 (7 bytes) bDescriptorType : 0x05 (Endpoint Descriptor) bEndpointAddress : 0x81 (Direction=IN EndpointID=1) bmAttributes : 0x02 (TransferType=Bulk) -wMaxPacketSize : 0x0040 (max 64 bytes) +wMaxPacketSize : 0x0040 (max 64 bytes for FS, 512 bytes for HS) bInterval : 0x00 (never NAKs) Data (HexDump) : 07 05 81 02 40 00 00 @@ -72,7 +72,7 @@ bLength : 0x07 (7 bytes) bDescriptorType : 0x05 (Endpoint Descriptor) bEndpointAddress : 0x02 (Direction=OUT EndpointID=2) bmAttributes : 0x02 (TransferType=Bulk) -wMaxPacketSize : 0x0040 (max 64 bytes) +wMaxPacketSize : 0x0040 (max 64 bytes for FS, 512 bytest for HS) bInterval : 0x00 (never NAKs) Data (HexDump) : 07 05 02 02 40 00 00 @@ -85,8 +85,12 @@ extern uint8_t mock_msc_scsi_config_desc[255]; extern uint16_t mock_msc_scsi_str_desc_manu[128]; extern uint16_t mock_msc_scsi_str_desc_prod[128]; extern uint16_t mock_msc_scsi_str_desc_ser_num[128]; -extern const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc; -extern const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc; +extern usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc; +extern usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc; +extern const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc_fs; +extern const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc_fs; +extern const usb_ep_desc_t mock_msc_scsi_bulk_out_ep_desc_hs; +extern const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc_hs; #define MOCK_MSC_SCSI_DEV_ID_VENDOR 0x0781 // Western Digital, Sandisk #define MOCK_MSC_SCSI_DEV_ID_PRODUCT 0x5595 @@ -99,7 +103,8 @@ extern const usb_ep_desc_t mock_msc_scsi_bulk_in_ep_desc; #define MOCK_MSC_SCSI_INTF_ALT_SETTING 0 #define MOCK_MSC_SCSI_BULK_OUT_EP_ADDR 0x02 #define MOCK_MSC_SCSI_BULK_IN_EP_ADDR 0x81 -#define MOCK_MSC_SCSI_BULK_EP_MPS 64 +#define MOCK_MSC_SCSI_BULK_EP_MPS_FS 64 // FS wMaxPacketSize +#define MOCK_MSC_SCSI_BULK_EP_MPS_HS 512 // HS wMaxPacketSize #define MOCK_MSC_SCSI_STRING_1 (" USB") #define MOCK_MSC_SCSI_STRING_2 (" SanDisk 3.2Gen1") #define MOCK_MSC_SCSI_STRING_3 ("0101cdd1e856b427bbb796f870561a4b2b817af9da9872c8d75217cccdd5d5eccb3a0000000000000000000096abe1a3ff83610095558107aea948b4") // This string is NOT checked by the enum test diff --git a/components/usb/test_apps/hcd/main/test_hcd_bulk.c b/components/usb/test_apps/hcd/main/test_hcd_bulk.c index b22273752a..5ad852f590 100644 --- a/components/usb/test_apps/hcd/main/test_hcd_bulk.c +++ b/components/usb/test_apps/hcd/main/test_hcd_bulk.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -61,6 +61,7 @@ TEST_CASE("Test HCD bulk pipe URBs", "[bulk][full_speed]") hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); //Create a default pipe (using a NULL EP descriptor) uint8_t dev_addr = test_hcd_enum_device(default_pipe); mock_msc_reset_req(default_pipe); + test_hcd_set_mock_msc_ep_descriptor(port_speed); //Create BULK IN and BULK OUT pipes for SCSI hcd_pipe_handle_t bulk_out_pipe = test_hcd_pipe_alloc(port_hdl, &mock_msc_scsi_bulk_out_ep_desc, dev_addr, port_speed); diff --git a/components/usb/test_apps/hcd/main/test_hcd_common.c b/components/usb/test_apps/hcd/main/test_hcd_common.c index 80c52e82ab..219e552cc4 100644 --- a/components/usb/test_apps/hcd/main/test_hcd_common.c +++ b/components/usb/test_apps/hcd/main/test_hcd_common.c @@ -19,6 +19,7 @@ #include "usb/usb_types_ch9.h" #include "test_hcd_common.h" #include "test_usb_common.h" +#include "test_usb_mock_msc.h" #include "unity.h" #include "esp_dma_utils.h" @@ -328,3 +329,14 @@ uint8_t test_hcd_enum_device(hcd_pipe_handle_t default_pipe) test_hcd_free_urb(urb); return ENUM_ADDR; } + +void test_hcd_set_mock_msc_ep_descriptor(usb_speed_t port_speed) +{ + if (port_speed == USB_SPEED_HIGH) { + mock_msc_scsi_bulk_out_ep_desc = mock_msc_scsi_bulk_out_ep_desc_hs; // HS wMaxPacketSize = 512 + mock_msc_scsi_bulk_in_ep_desc = mock_msc_scsi_bulk_in_ep_desc_hs; + } else { + mock_msc_scsi_bulk_out_ep_desc = mock_msc_scsi_bulk_out_ep_desc_fs; // FS wMaxPacketSize = 64 + mock_msc_scsi_bulk_in_ep_desc = mock_msc_scsi_bulk_in_ep_desc_fs; + } +} diff --git a/components/usb/test_apps/hcd/main/test_hcd_common.h b/components/usb/test_apps/hcd/main/test_hcd_common.h index 6d772db672..316f917df2 100644 --- a/components/usb/test_apps/hcd/main/test_hcd_common.h +++ b/components/usb/test_apps/hcd/main/test_hcd_common.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -136,3 +136,12 @@ void test_hcd_free_urb(urb_t *urb); * @return uint8_t The address of the device after enumeration */ uint8_t test_hcd_enum_device(hcd_pipe_handle_t default_pipe); + +/** + * @brief Set endpoint descriptor + * + * Set endpoint descriptor of the mock device with different wMaxPacketSize according to the connected device's speed + * + * @param port_speed Port speed after the device is connected + */ +void test_hcd_set_mock_msc_ep_descriptor(usb_speed_t port_speed); diff --git a/components/usb/test_apps/hcd/main/test_usb_helpers.c b/components/usb/test_apps/hcd/main/test_usb_helpers.c index 1d589118d9..fafe81c032 100644 --- a/components/usb/test_apps/hcd/main/test_usb_helpers.c +++ b/components/usb/test_apps/hcd/main/test_usb_helpers.c @@ -428,7 +428,7 @@ static void test_parse_ep_by_address(const usb_config_desc_t *config_desc) TEST_ASSERT_NULL(ep_desc); } -TEST_CASE("Test USB Helpers descriptor parsing", "[helpers][full_speed]") +TEST_CASE("Test USB Helpers descriptor parsing", "[helpers][full_speed][high_speed]") { const usb_config_desc_t *config_desc = (const usb_config_desc_t *)config_desc_bytes; test_walk_desc(config_desc); diff --git a/components/usb/test_apps/hcd/pytest_usb_hcd.py b/components/usb/test_apps/hcd/pytest_usb_hcd.py index 8498cb2403..7df14e1779 100644 --- a/components/usb/test_apps/hcd/pytest_usb_hcd.py +++ b/components/usb/test_apps/hcd/pytest_usb_hcd.py @@ -7,7 +7,10 @@ from pytest_embedded import Dut @pytest.mark.esp32s2 @pytest.mark.esp32s3 @pytest.mark.esp32p4 -@pytest.mark.temp_skip_ci(targets=['esp32s2', 'esp32p4'], reason='lack of runners with usb_host_flash_disk tag') +@pytest.mark.temp_skip_ci(targets=['esp32s2'], reason='lack of runners with usb_host_flash_disk tag') @pytest.mark.usb_host_flash_disk def test_usb_hcd(dut: Dut) -> None: - dut.run_all_single_board_cases(group='full_speed') + if (dut.target == 'esp32s3'): + dut.run_all_single_board_cases(group='full_speed') + else: + dut.run_all_single_board_cases(group='high_speed') diff --git a/components/usb/test_apps/usb_host/main/msc_client_async_dconn.c b/components/usb/test_apps/usb_host/main/msc_client_async_dconn.c index 4f1e96b8d9..af6bc5435b 100644 --- a/components/usb/test_apps/usb_host/main/msc_client_async_dconn.c +++ b/components/usb/test_apps/usb_host/main/msc_client_async_dconn.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -55,6 +55,7 @@ typedef struct { usb_device_handle_t dev_hdl; int num_data_transfers; int event_count; + usb_speed_t dev_speed; } msc_client_obj_t; static void msc_reset_cbw_transfer_cb(usb_transfer_t *transfer) @@ -188,6 +189,10 @@ void msc_client_async_dconn_task(void *arg) TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_device_descriptor(msc_obj.dev_hdl, &device_desc)); TEST_ASSERT_EQUAL(msc_obj.test_param.idVendor, device_desc->idVendor); TEST_ASSERT_EQUAL(msc_obj.test_param.idProduct, device_desc->idProduct); + //Get device info to get device speed + usb_device_info_t dev_info; + TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info)); + msc_obj.dev_speed = dev_info.speed; //Claim the MSC interface TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_claim(msc_obj.client_hdl, msc_obj.dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING)); msc_obj.next_stage = TEST_STAGE_MSC_RESET; @@ -216,8 +221,11 @@ void msc_client_async_dconn_task(void *arg) case TEST_STAGE_MSC_DATA_DCONN: { ESP_LOGD(MSC_CLIENT_TAG, "Data and disconnect"); //Setup the Data IN transfers + const int bulk_ep_mps = (msc_obj.dev_speed == USB_SPEED_HIGH) + ? MOCK_MSC_SCSI_BULK_EP_MPS_HS + : MOCK_MSC_SCSI_BULK_EP_MPS_FS; for (int i = 0; i < msc_obj.num_data_transfers; i++) { - xfer_in[i]->num_bytes = usb_round_up_to_mps(MOCK_MSC_SCSI_SECTOR_SIZE, MOCK_MSC_SCSI_BULK_EP_MPS); + xfer_in[i]->num_bytes = usb_round_up_to_mps(MOCK_MSC_SCSI_SECTOR_SIZE, bulk_ep_mps); xfer_in[i]->bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR; } //Submit those transfers diff --git a/components/usb/test_apps/usb_host/main/msc_client_async_enum.c b/components/usb/test_apps/usb_host/main/msc_client_async_enum.c index f0a72bd69c..38da2aee23 100644 --- a/components/usb/test_apps/usb_host/main/msc_client_async_enum.c +++ b/components/usb/test_apps/usb_host/main/msc_client_async_enum.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -48,6 +48,7 @@ typedef struct { uint8_t dev_addr_to_open; usb_host_client_handle_t client_hdl; usb_device_handle_t dev_hdl; + usb_speed_t dev_speed; } msc_client_obj_t; static void msc_client_event_cb(const usb_host_client_event_msg_t *event_msg, void *arg) @@ -66,6 +67,24 @@ static void msc_client_event_cb(const usb_host_client_event_msg_t *event_msg, vo } } +static void mock_msc_scsi_init_reference_ep_descriptors(const msc_client_obj_t *msc_obj) +{ + uint8_t *dest_ptr = mock_msc_scsi_config_desc; + dest_ptr += USB_CONFIG_DESC_SIZE; + dest_ptr += USB_INTF_DESC_SIZE; + + const usb_ep_desc_t en_desc_in = (msc_obj->dev_speed == USB_SPEED_HIGH) + ? mock_msc_scsi_bulk_in_ep_desc_hs + : mock_msc_scsi_bulk_in_ep_desc_fs; + const usb_ep_desc_t en_desc_out = (msc_obj->dev_speed == USB_SPEED_HIGH) + ? mock_msc_scsi_bulk_out_ep_desc_hs + : mock_msc_scsi_bulk_out_ep_desc_fs; + + memcpy(dest_ptr, (void*)&en_desc_in, sizeof(en_desc_in)); + dest_ptr += USB_EP_DESC_SIZE; + memcpy(dest_ptr, (void*)&en_desc_out, sizeof(en_desc_out)); +} + void msc_client_async_enum_task(void *arg) { msc_client_obj_t msc_obj; @@ -113,6 +132,11 @@ void msc_client_async_enum_task(void *arg) //Open the device TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_open(msc_obj.client_hdl, msc_obj.dev_addr_to_open, &msc_obj.dev_hdl)); msc_obj.next_stage = TEST_STAGE_CHECK_DEV_DESC; + //Get device info to get device speed + usb_device_info_t dev_info; + TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info)); + msc_obj.dev_speed = dev_info.speed; + mock_msc_scsi_init_reference_ep_descriptors(&msc_obj); skip_event_handling = true; //Need to execute TEST_STAGE_CHECK_DEV_DESC break; } diff --git a/components/usb/test_apps/usb_host/main/msc_client_async_seq.c b/components/usb/test_apps/usb_host/main/msc_client_async_seq.c index 6eff7d3d3d..69187ea583 100644 --- a/components/usb/test_apps/usb_host/main/msc_client_async_seq.c +++ b/components/usb/test_apps/usb_host/main/msc_client_async_seq.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -53,6 +53,7 @@ typedef struct { usb_host_client_handle_t client_hdl; usb_device_handle_t dev_hdl; int num_sectors_read; + usb_speed_t dev_speed; } msc_client_obj_t; static void msc_transfer_cb(usb_transfer_t *transfer) @@ -141,7 +142,7 @@ void msc_client_async_seq_task(void *arg) usb_transfer_t *xfer_out = NULL; //Must be large enough to contain CBW and MSC reset control transfer usb_transfer_t *xfer_in = NULL; //Must be large enough to contain CSW and Data size_t out_worst_case_size = MAX(sizeof(mock_msc_bulk_cbw_t), sizeof(usb_setup_packet_t)); - size_t in_worst_case_size = usb_round_up_to_mps(MAX(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj.test_param.num_sectors_per_xfer, sizeof(mock_msc_bulk_csw_t)), MOCK_MSC_SCSI_BULK_EP_MPS); + size_t in_worst_case_size = usb_round_up_to_mps(MAX(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj.test_param.num_sectors_per_xfer, sizeof(mock_msc_bulk_csw_t)), MOCK_MSC_SCSI_BULK_EP_MPS_HS); TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_alloc(out_worst_case_size, 0, &xfer_out)); TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_alloc(in_worst_case_size, 0, &xfer_in)); xfer_out->callback = msc_transfer_cb; @@ -178,6 +179,10 @@ void msc_client_async_seq_task(void *arg) TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_device_descriptor(msc_obj.dev_hdl, &device_desc)); TEST_ASSERT_EQUAL(msc_obj.test_param.idVendor, device_desc->idVendor); TEST_ASSERT_EQUAL(msc_obj.test_param.idProduct, device_desc->idProduct); + //Get device info to get device speed + usb_device_info_t dev_info; + TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info)); + msc_obj.dev_speed = dev_info.speed; //Claim the MSC interface TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_claim(msc_obj.client_hdl, msc_obj.dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING)); msc_obj.next_stage = TEST_STAGE_MSC_RESET; @@ -209,7 +214,10 @@ void msc_client_async_seq_task(void *arg) } case TEST_STAGE_MSC_DATA: { ESP_LOGD(MSC_CLIENT_TAG, "Data"); - xfer_in->num_bytes = usb_round_up_to_mps(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj.test_param.num_sectors_per_xfer, MOCK_MSC_SCSI_BULK_EP_MPS); + const int bulk_ep_mps = (msc_obj.dev_speed == USB_SPEED_HIGH) + ? MOCK_MSC_SCSI_BULK_EP_MPS_HS + : MOCK_MSC_SCSI_BULK_EP_MPS_FS; + xfer_in->num_bytes = usb_round_up_to_mps(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj.test_param.num_sectors_per_xfer, bulk_ep_mps); xfer_in->bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR; TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_in)); //Test that an inflight transfer cannot be resubmitted @@ -219,7 +227,10 @@ void msc_client_async_seq_task(void *arg) } case TEST_STAGE_MSC_CSW: { ESP_LOGD(MSC_CLIENT_TAG, "CSW"); - xfer_in->num_bytes = usb_round_up_to_mps(sizeof(mock_msc_bulk_csw_t), MOCK_MSC_SCSI_BULK_EP_MPS); + const int bulk_ep_mps = (msc_obj.dev_speed == USB_SPEED_HIGH) + ? MOCK_MSC_SCSI_BULK_EP_MPS_HS + : MOCK_MSC_SCSI_BULK_EP_MPS_FS; + xfer_in->num_bytes = usb_round_up_to_mps(sizeof(mock_msc_bulk_csw_t), bulk_ep_mps); xfer_in->bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR; TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_in)); //Test that an inflight transfer cannot be resubmitted diff --git a/components/usb/test_apps/usb_host/main/test_usb_host_async.c b/components/usb/test_apps/usb_host/main/test_usb_host_async.c index 6e5b9cef0e..98b978acf9 100644 --- a/components/usb/test_apps/usb_host/main/test_usb_host_async.c +++ b/components/usb/test_apps/usb_host/main/test_usb_host_async.c @@ -44,7 +44,7 @@ Procedure: - Uninstall USB Host Library */ -TEST_CASE("Test USB Host async client (single client)", "[usb_host][full_speed]") +TEST_CASE("Test USB Host async client (single client)", "[usb_host][full_speed][high_speed]") { //Create task to run client that communicates with MSC SCSI interface msc_client_test_param_t params = { @@ -94,7 +94,7 @@ Procedure: - Free all devices - Uninstall USB Host Library */ -TEST_CASE("Test USB Host async client (multi client)", "[usb_host][full_speed]") +TEST_CASE("Test USB Host async client (multi client)", "[usb_host][full_speed][high_speed]") { //Create task to run the MSC client msc_client_test_param_t msc_params = { 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 63025a6a3a..309ba6e510 100644 --- a/components/usb/test_apps/usb_host/pytest_usb_host.py +++ b/components/usb/test_apps/usb_host/pytest_usb_host.py @@ -7,7 +7,10 @@ from pytest_embedded import Dut @pytest.mark.esp32s2 @pytest.mark.esp32s3 @pytest.mark.esp32p4 -@pytest.mark.temp_skip_ci(targets=['esp32s2', 'esp32p4'], reason='lack of runners with usb_host_flash_disk tag') +@pytest.mark.temp_skip_ci(targets=['esp32s2'], reason='lack of runners with usb_host_flash_disk tag') @pytest.mark.usb_host_flash_disk def test_usb_host(dut: Dut) -> None: - dut.run_all_single_board_cases(group='full_speed') + if (dut.target == 'esp32s3'): + dut.run_all_single_board_cases(group='full_speed') + else: + dut.run_all_single_board_cases(group='high_speed') diff --git a/examples/peripherals/.build-test-rules.yml b/examples/peripherals/.build-test-rules.yml index 779e60fa70..dbc92f515a 100644 --- a/examples/peripherals/.build-test-rules.yml +++ b/examples/peripherals/.build-test-rules.yml @@ -450,7 +450,7 @@ examples/peripherals/usb/host: disable: - if: SOC_USB_OTG_SUPPORTED != 1 disable_test: - - if: IDF_TARGET not in ["esp32s3"] + - if: IDF_TARGET not in ["esp32s3", "esp32p4"] temporary: true reason: lack of runners with usb_host_flash_disk tag depends_components: diff --git a/examples/peripherals/usb/device/tusb_msc/pytest_usb_device_msc.py b/examples/peripherals/usb/device/tusb_msc/pytest_usb_device_msc.py index dc730667b8..bac44fe8c1 100644 --- a/examples/peripherals/usb/device/tusb_msc/pytest_usb_device_msc.py +++ b/examples/peripherals/usb/device/tusb_msc/pytest_usb_device_msc.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest from pytest_embedded import Dut @@ -13,6 +13,6 @@ def test_usb_device_msc_example(dut: Dut) -> None: dut.expect('Mount storage') dut.expect('TinyUSB Driver installed') dut.expect('USB MSC initialization DONE') - dut.expect('esp32s2>') + dut.expect(dut.target + '>') dut.write('status') dut.expect('storage exposed over USB') diff --git a/examples/peripherals/usb/host/msc/pytest_usb_host_msc.py b/examples/peripherals/usb/host/msc/pytest_usb_host_msc.py index 44e1444b3b..cae9851d4c 100644 --- a/examples/peripherals/usb/host/msc/pytest_usb_host_msc.py +++ b/examples/peripherals/usb/host/msc/pytest_usb_host_msc.py @@ -7,9 +7,12 @@ from pytest_embedded import Dut @pytest.mark.esp32s2 @pytest.mark.esp32s3 @pytest.mark.esp32p4 -@pytest.mark.temp_skip_ci(targets=['esp32s2', 'esp32p4'], reason='lack of runners with usb_host_flash_disk tag') +@pytest.mark.temp_skip_ci(targets=['esp32s2'], reason='lack of runners with usb_host_flash_disk tag') @pytest.mark.usb_host_flash_disk def test_usb_host_msc_example(dut: Dut) -> None: + # Get wMaxPacketSize to get USB device speed + max_packet_size = int(dut.expect(r'wMaxPacketSize (\d{2,3})')[1].decode()) + # Check result of file_operations() dut.expect_exact("example: Read from file '/usb/esp/test.txt': 'Hello World!'") @@ -17,12 +20,20 @@ def test_usb_host_msc_example(dut: Dut) -> None: write_throughput = float(dut.expect(r'example: Write speed ([0-9]*[.]?[0-9]+) MiB')[1].decode()) read_throughput = float(dut.expect(r'example: Read speed ([0-9]*[.]?[0-9]+) MiB')[1].decode()) + # Set write and read throughput limits + if (max_packet_size == 512): # wMaxPacketSize = 512 for HS + write_throughput_limit = 4.9 + read_throughput_limit = 11.5 + else: # wMaxPacketSize = 64 for FS + write_throughput_limit = 0.9 + read_throughput_limit = 1.0 + # These values should be updated for HS targets - if write_throughput > 0.9: + if write_throughput > write_throughput_limit: print('Write throughput put OK') else: print('write throughput too slow!') - if read_throughput > 1.0: + if read_throughput > read_throughput_limit: print('Read throughput put OK') else: print('Read throughput too slow!') diff --git a/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c b/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c index 2a8b4c2dbf..0776c741c7 100644 --- a/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c +++ b/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c @@ -72,7 +72,9 @@ static void action_get_info(class_driver_t *driver_obj) ESP_LOGI(TAG, "Getting device information"); usb_device_info_t dev_info; ESP_ERROR_CHECK(usb_host_device_info(driver_obj->dev_hdl, &dev_info)); - ESP_LOGI(TAG, "\t%s speed", (dev_info.speed == USB_SPEED_LOW) ? "Low" : "Full"); + ESP_LOGI(TAG, "\t%s speed", (char *[]) { + "Low", "Full", "High" + }[dev_info.speed]); ESP_LOGI(TAG, "\tbConfigurationValue %d", dev_info.bConfigurationValue); //Get the device descriptor next diff --git a/examples/peripherals/usb/host/usb_host_lib/pytest_usb_host_lib.py b/examples/peripherals/usb/host/usb_host_lib/pytest_usb_host_lib.py new file mode 100644 index 0000000000..4f1e0a3168 --- /dev/null +++ b/examples/peripherals/usb/host/usb_host_lib/pytest_usb_host_lib.py @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.esp32p4 +@pytest.mark.temp_skip_ci(targets=['esp32s2'], reason='lack of runners with usb_host_flash_disk tag') +@pytest.mark.usb_host_flash_disk +def test_usb_host_lib_example(dut: Dut) -> None: + # register client + dut.expect_exact('CLASS: Registering Client') + + # expect device descriptor + dut.expect_exact('CLASS: Getting device descriptor') + + # confirm device descriptor + dut.expect_exact('*** Device descriptor ***') + + # expect configuration descriptor + dut.expect_exact('CLASS: Getting config descriptor') + + # confirm configuration descriptor + dut.expect_exact('*** Configuration descriptor ***')