From 5e406f41c1f26b1a41fe489f6a0beda772228790 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Thu, 23 Feb 2023 17:53:42 +0800 Subject: [PATCH] move ep0 active into hub event --- class/hub/usbh_hub.c | 11 ++++++++--- core/usbh_core.c | 7 ------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index 09557d3a..c0506e6e 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -509,18 +509,22 @@ static void usbh_hub_events(struct usbh_hub *hub) child->connected = true; child->port = port + 1; child->speed = speed; - + USB_LOG_INFO("New %s device on Hub %u, Port %u connected\r\n", speed_table[speed], hub->index, port + 1); + /* Configure EP0 with the default maximum packet size */ + usbh_hport_activate_ep0(child); + if (usbh_enumerate(child) < 0) { + /** release child sources */ + usbh_hubport_release(child); USB_LOG_ERR("Port %u enumerate fail\r\n", port + 1); } } else { - USB_LOG_ERR("Failed to enable port %u\r\n", port + 1); - child = &hub->child[port]; /** release child sources */ usbh_hubport_release(child); + USB_LOG_ERR("Failed to enable port %u\r\n", port + 1); continue; } @@ -528,6 +532,7 @@ static void usbh_hub_events(struct usbh_hub *hub) child = &hub->child[port]; /** release child sources */ usbh_hubport_release(child); + USB_LOG_INFO("Device on Hub %u, Port %u disconnected\r\n", hub->index, port + 1); } } } diff --git a/core/usbh_core.c b/core/usbh_core.c index 03741619..3a231d66 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -419,9 +419,6 @@ int usbh_enumerate(struct usbh_hubport *hport) hport->setup = &g_setup[hport->parent->index - 1][hport->port - 1]; setup = hport->setup; - /* Configure EP0 with the default maximum packet size */ - usbh_hport_activate_ep0(hport); - /* Read the first 8 bytes of the device descriptor */ setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_DEVICE; setup->bRequest = USB_REQUEST_GET_DESCRIPTOR; @@ -629,10 +626,6 @@ int usbh_enumerate(struct usbh_hubport *hport) } errout: - if (ret < 0) { - hport->config.config_desc.bNumInterfaces = 0; - usbh_hport_deactivate_ep0(hport); - } if (hport->raw_config_desc) { usb_free(hport->raw_config_desc); hport->raw_config_desc = NULL;