From 7098d42b870d88d7efa4cb597abf4b6b9bda6d3e Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Mon, 1 Dec 2025 20:30:18 +0800 Subject: [PATCH] update(port/dwc2/usb_hc_dwc2): reset channel with dwc2_halt in deinit Signed-off-by: sakumisu <1203593632@qq.com> --- port/dwc2/usb_hc_dwc2.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c index 8a7ad9a8..4b6143b1 100644 --- a/port/dwc2/usb_hc_dwc2.c +++ b/port/dwc2/usb_hc_dwc2.c @@ -797,7 +797,6 @@ int usb_hc_init(struct usbh_bus *bus) int usb_hc_deinit(struct usbh_bus *bus) { volatile uint32_t count = 0U; - uint32_t value; USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_GINT; @@ -805,27 +804,8 @@ int usb_hc_deinit(struct usbh_bus *bus) dwc2_flush_rxfifo(bus); /* Flush out any leftover queued requests. */ - for (uint32_t i = 0U; i < g_dwc2_hcd[bus->hcd.hcd_id].hw_params.host_channels; i++) { - value = USB_OTG_HC(i)->HCCHAR; - value |= USB_OTG_HCCHAR_CHDIS; - value &= ~USB_OTG_HCCHAR_CHENA; - value &= ~USB_OTG_HCCHAR_EPDIR; - USB_OTG_HC(i)->HCCHAR = value; - } - - /* Halt all channels to put them into a known state. */ - for (uint32_t i = 0U; i < g_dwc2_hcd[bus->hcd.hcd_id].hw_params.host_channels; i++) { - value = USB_OTG_HC(i)->HCCHAR; - value |= USB_OTG_HCCHAR_CHDIS; - value |= USB_OTG_HCCHAR_CHENA; - value &= ~USB_OTG_HCCHAR_EPDIR; - USB_OTG_HC(i)->HCCHAR = value; - - do { - if (++count > 1000U) { - return -USB_ERR_TIMEOUT; - } - } while ((USB_OTG_HC(i)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA); + for (uint8_t chidx = 0; chidx < g_dwc2_hcd[bus->hcd.hcd_id].hw_params.host_channels; chidx++) { + dwc2_halt(bus, chidx); } /* Disable all interrupts. */