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;