This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 44ee275c919cdc687038063279ebd1d00efd5349
Author: raiden00pl <[email protected]>
AuthorDate: Fri Nov 20 11:21:59 2026 +0100

    arch/arm/stm32: Wait for the port enable after the OTG host port reset.
    
    A device can disconnect and reconnect after the root port reset.  The
    connect interrupt then resets the port again while the first SETUP is
    in flight, and the control transfer never completes.  Wait until the
    port is enabled and for the reset recovery time before enumerating.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 arch/arm/src/common/stm32/stm32_otghost_v2.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/arm/src/common/stm32/stm32_otghost_v2.c 
b/arch/arm/src/common/stm32/stm32_otghost_v2.c
index d92fc2e8be8..946817e263e 100644
--- a/arch/arm/src/common/stm32/stm32_otghost_v2.c
+++ b/arch/arm/src/common/stm32/stm32_otghost_v2.c
@@ -3944,6 +3944,7 @@ static int stm32_rh_enumerate(struct stm32_usbhost_s 
*priv,
 {
   uint32_t regval;
   int ret;
+  int i;
 
   DEBUGASSERT(conn != NULL && hport != NULL && hport->port == 0);
 
@@ -3971,6 +3972,24 @@ static int stm32_rh_enumerate(struct stm32_usbhost_s 
*priv,
 
   stm32_portreset(priv);
 
+  /* Wait until the port is enabled.  A device can reconnect after the
+   * reset, and the connect interrupt then resets the port again.
+   */
+
+  for (i = 0; (stm32_getreg(STM32_OTG_HPRT) & OTG_HPRT_PENA) == 0; i++)
+    {
+      if (i >= 50)
+        {
+          return -ENODEV;
+        }
+
+      nxsched_usleep(10 * 1000);
+    }
+
+  /* USB 2.0 reset recovery time */
+
+  nxsched_usleep(10 * 1000);
+
   /* Get the current device speed */
 
   regval = stm32_getreg(STM32_OTG_HPRT);

Reply via email to