add reset port timeout check for dwc2

This commit is contained in:
udoudou
2025-07-27 17:53:10 +08:00
committed by sakumisu
parent c102f4adfa
commit 1a68d94c32
2 changed files with 8 additions and 2 deletions

View File

@@ -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) static int usbh_reset_port(struct usbh_bus *bus, const uint8_t port)
{ {
__IO uint32_t hprt0 = 0U; __IO uint32_t hprt0 = 0U;
volatile uint32_t timeout = 0;
hprt0 = USB_OTG_HPRT; 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)) { if (!(USB_OTG_HPRT & USB_OTG_HPRT_PCSTS)) {
return -USB_ERR_NOTCONN; /* Port not connected */ 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); usb_osal_msleep(10U);
} }
return 0; return 0;
@@ -907,7 +913,7 @@ int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, u
dwc2_drivebus(bus, 1); dwc2_drivebus(bus, 1);
break; break;
case HUB_PORT_FEATURE_RESET: case HUB_PORT_FEATURE_RESET:
usbh_reset_port(bus, port); return usbh_reset_port(bus, port);
break; break;
default: default:

View File

@@ -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; EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_PP;
break; break;
case HUB_PORT_FEATURE_RESET: case HUB_PORT_FEATURE_RESET:
usbh_reset_port(bus, port); return usbh_reset_port(bus, port);
#ifdef CONFIG_USB_EHCI_WITH_OHCI #ifdef CONFIG_USB_EHCI_WITH_OHCI
if (!(EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_PE)) { if (!(EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_PE)) {
EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_OWNER; EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_OWNER;