Skip to main content
Associate III
August 11, 2025
Solved

USB CoreReset stuck at count

  • August 11, 2025
  • 1 reply
  • 256 views

Hi all

 

static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx)
{
 __IO uint32_t count = 0U;

 /* Wait for AHB master IDLE state. */
 do
 {
 count++;

 if (count > HAL_USB_TIMEOUT)
 {
 return HAL_TIMEOUT;
 }
 } while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_AHBIDL) == 0U);

 count = 10U;

 /* few cycles before setting core reset */
 while (count > 0U)
 {
 count--;
 }

 /* Core Soft Reset */
 USBx->GRSTCTL |= USB_OTG_GRSTCTL_CSRST;

 do
 {
 count++;

 if (count > HAL_USB_TIMEOUT)
 {
 return HAL_TIMEOUT;
 }
 } while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_CSRST) == USB_OTG_GRSTCTL_CSRST);

 return HAL_OK;
}

 

at the USB_CoreReset function, my code keeps on getting stuck at the count++ and doesn't progress from there. 

I have even included 

 
 RCC->AHB2ENR1 |= RCC_AHB2ENR1_OTGEN; // enable USB OTG HS clock
 RCC->AHB2ENR1 |= RCC_AHB2ENR1_USBPHYCEN; // enable ULPI clock

 

before that function call but it does nothing.
My board is stm32u5g9.

Thank you and kind regards

 

Best answer by Maaz1

The solution was 

 RCC->AHB2ENR1 |= RCC_AHB2ENR1_OTGEN; // enable USB OTG HS clock
 RCC->AHB2ENR1 |= RCC_AHB2ENR1_USBPHYCEN; // OTG_HS PHY clock enable
 RCC->APB3ENR |= RCC_APB3ENR_SYSCFGEN;

 

especially the last line of code

1 reply

Maaz1AuthorBest answer
Associate III
August 13, 2025

The solution was 

 RCC->AHB2ENR1 |= RCC_AHB2ENR1_OTGEN; // enable USB OTG HS clock
 RCC->AHB2ENR1 |= RCC_AHB2ENR1_USBPHYCEN; // OTG_HS PHY clock enable
 RCC->APB3ENR |= RCC_APB3ENR_SYSCFGEN;

 

especially the last line of code