From b79f097e36d5656b18d9d1e7b5fbea14f692618f Mon Sep 17 00:00:00 2001
From: gdisirio <gdisirio@110e8d01-0319-4d1e-a829-52ad28d1bb01>
Date: Sun, 16 Dec 2018 07:52:19 +0000
Subject: Tentative fix for
 http://www.chibios.com/forum/viewtopic.php?f=35&t=4918&p=34444

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12471 110e8d01-0319-4d1e-a829-52ad28d1bb01
---
 os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c b/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c
index 3ff3bc9f0..0357d1855 100644
--- a/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c
+++ b/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c
@@ -134,7 +134,9 @@ static const stm32_otg_params_t hsparams = {
 static void otg_core_reset(USBDriver *usbp) {
   stm32_otg_t *otgp = usbp->otg;
 
-  osalSysPolledDelayX(32);
+  /* Wait AHB idle condition.*/
+  while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0)
+    ;
 
   /* Core reset and delay of at least 3 PHY cycles.*/
   otgp->GRSTCTL = GRSTCTL_CSRST;
@@ -143,7 +145,7 @@ static void otg_core_reset(USBDriver *usbp) {
 
   osalSysPolledDelayX(18);
 
-  /* Wait AHB idle condition.*/
+  /* Wait AHB idle condition again.*/
   while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0)
     ;
 }
-- 
cgit v1.2.3