fix(usb/host): Correctly handle unpowered port in HUB

This commit is contained in:
Tomas Rezucha
2024-09-27 11:31:42 +02:00
parent 802ab4c2cc
commit 9bdea61071
5 changed files with 37 additions and 16 deletions
@@ -88,8 +88,10 @@ static void msc_data_transfer_cb(usb_transfer_t *transfer)
// The data stage should have either completed, or failed due to the disconnection.
TEST_ASSERT(transfer->status == USB_TRANSFER_STATUS_COMPLETED || transfer->status == USB_TRANSFER_STATUS_NO_DEVICE);
if (transfer->status == USB_TRANSFER_STATUS_COMPLETED) {
printf("Data transfer completed\n");
TEST_ASSERT_EQUAL(transfer->num_bytes, transfer->actual_num_bytes);
} else {
printf("Data transfer NOT completed: No device\n");
TEST_ASSERT_EQUAL(0, transfer->actual_num_bytes);
}
msc_client_obj_t *msc_obj = (msc_client_obj_t *)transfer->context;
@@ -238,7 +240,7 @@ void msc_client_async_dconn_task(void *arg)
break;
}
case TEST_STAGE_MSC_DATA_DCONN: {
ESP_LOGD(MSC_CLIENT_TAG, "Data and disconnect");
ESP_LOGD(MSC_CLIENT_TAG, "Data (%d transfers) and disconnect", msc_obj.num_data_transfers);
// Setup the Data IN transfers
const usb_ep_desc_t *in_ep_desc = dev_msc_get_in_ep_desc(msc_obj.dev_speed);
const int bulk_ep_mps = USB_EP_DESC_GET_MPS(in_ep_desc);
@@ -259,8 +261,11 @@ void msc_client_async_dconn_task(void *arg)
ESP_LOGD(MSC_CLIENT_TAG, "Close");
TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_release(msc_obj.client_hdl, msc_obj.dev_hdl, msc_obj.dev_info->bInterfaceNumber));
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_close(msc_obj.client_hdl, msc_obj.dev_hdl));
dconn_iter++;
if (dconn_iter < TEST_DCONN_ITERATIONS) {
vTaskDelay(10); // Yield to USB Host task so it can handle the disconnection
// The device has disconnected and it's disconnection has been handled
printf("Dconn iter %d done\n", dconn_iter);
if (++dconn_iter < TEST_DCONN_ITERATIONS) {
// Start the next test iteration by going back to TEST_STAGE_WAIT_CONN and reenabling connections
msc_obj.next_stage = TEST_STAGE_WAIT_CONN;
skip_event_handling = true; // Need to execute TEST_STAGE_WAIT_CONN
@@ -177,6 +177,7 @@ void msc_client_async_enum_task(void *arg)
if (enum_iter < TEST_ENUM_ITERATIONS) {
// Start the next test iteration by disconnecting the device, then going back to TEST_STAGE_WAIT_CONN stage
usb_host_lib_set_root_port_power(false);
vTaskDelay(10); // Yield to USB Host task so it can handle the disconnection
usb_host_lib_set_root_port_power(true);
msc_obj.next_stage = TEST_STAGE_WAIT_CONN;
skip_event_handling = true; // Need to execute TEST_STAGE_WAIT_CONN
@@ -31,6 +31,7 @@ void tearDown(void)
// Short delay to allow task to be cleaned up
vTaskDelay(10);
// Clean up USB Host
printf("USB Host uninstall\n");
ESP_ERROR_CHECK(usb_host_uninstall());
// Short delay to allow task to be cleaned up after client uninstall
vTaskDelay(10);