summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorudoudou <[email protected]>2025-07-27 17:53:10 +0800
committersakumisu <[email protected]>2025-07-27 20:30:08 +0800
commit1a68d94c32b5e31988490c556e7ae384cd26e4b3 (patch)
tree4c459eddac6aa9987b58fb996bf2c484ee86b894
parentc102f4adfafb6ab7786e89955c9eacc9df27ccd5 (diff)
add reset port timeout check for dwc2
-rw-r--r--port/dwc2/usb_hc_dwc2.c8
-rw-r--r--port/ehci/usb_hc_ehci.c2
2 files changed, 8 insertions, 2 deletions
diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c
index 5a19ace5..838c7b3c 100644
--- a/port/dwc2/usb_hc_dwc2.c
+++ b/port/dwc2/usb_hc_dwc2.c
@@ -369,6 +369,7 @@ static void dwc2_halt(struct usbh_bus *bus, uint8_t ch_num)
static int usbh_reset_port(struct usbh_bus *bus, const uint8_t port)
{
__IO uint32_t hprt0 = 0U;
+ volatile uint32_t timeout = 0;
hprt0 = USB_OTG_HPRT;
@@ -384,6 +385,11 @@ static int usbh_reset_port(struct usbh_bus *bus, const uint8_t port)
if (!(USB_OTG_HPRT & USB_OTG_HPRT_PCSTS)) {
return -USB_ERR_NOTCONN; /* Port not connected */
}
+ timeout++;
+ if (timeout > 10) {
+ USB_LOG_ERR("Reset port timeout\r\n");
+ return -USB_ERR_TIMEOUT;
+ }
usb_osal_msleep(10U);
}
return 0;
@@ -907,7 +913,7 @@ int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, u
dwc2_drivebus(bus, 1);
break;
case HUB_PORT_FEATURE_RESET:
- usbh_reset_port(bus, port);
+ return usbh_reset_port(bus, port);
break;
default:
diff --git a/port/ehci/usb_hc_ehci.c b/port/ehci/usb_hc_ehci.c
index c6a72e0f..e88af6d4 100644
--- a/port/ehci/usb_hc_ehci.c
+++ b/port/ehci/usb_hc_ehci.c
@@ -1119,7 +1119,7 @@ int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, u
EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_PP;
break;
case HUB_PORT_FEATURE_RESET:
- usbh_reset_port(bus, port);
+ return usbh_reset_port(bus, port);
#ifdef CONFIG_USB_EHCI_WITH_OHCI
if (!(EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_PE)) {
EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_OWNER;