cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401 USB -- USB_CoreReset failed(CSRST bit stucked)

Peerless
Associate II

During debugging a bus-powered STM32F401RCT6 customed board, a strange problem was encountered. The application code is directly generated by CubeMX with USB CDC, VBUS sense disabled. The USB failed at plug-in, even no USB enumerating.

I tried to debug it with a stlink, and found the USB works when the board is firstly powered by the debugger before usb cable plugged in. If the MCU boots when the USB cable already plugged, the code goes to error at

USB_CoreReset()

The CSRST bit in register FS_GRSTCTL is not cleared. The code returns HAL_TINEOUT.

8 REPLIES 8
Imen.D
ST Employee

Hello,

Can you please provide more details on your issue : which CubeMx and CubeF4 firmware package versions used ? If possible share your ioc file to check more this behavior?

Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

You probably don't have set up a proper 48MHz clock, or have it set/enabled late.

JW

Thanks for your reply.

The CubeMX version is 5.1.0 and the CubeF4 package is 1.24.0.

The ioc file is attached. Only USB is enabled and the problem remains same.

Thks

I just created the project with CubeMX and no modification is made on the generated code.

The only difference between work or not is whether the usb cable is unplugged/plugged on power up.

Anyway, if you are familiar with the configuration of the USB clock, pls let me know how to check if it was set correctly.

I don't use CubeMX.

> let me know how to check if it was set correctly.

Just make sure the HSE and PLL are up and stable and properly set (so that 48MHz is at the Q tap of the PLL output) at the moment when you call the offending function.

JW

Peerless
Associate II

The problem is solved now (I guess).

It seems like there's something wrong within the generated code. A parameter was mismatched and something happened during USB configuration. The cubeMX is easy to use, but the USB code is really complex. Here's the code where I find the error:

void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{ 
   USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
 
  //if ( hpcd->Init.speed != PCD_SPEED_FULL)  <== this is the original version, but PCD_SPEED_FULL is 2U and the returned speed should be USB_OTG_SPEED_FULL, or 3U
	if ( hpcd->Init.speed != USB_OTG_SPEED_FULL) //<== the fixed version
  {
    Error_Handler();
  }
    /* Set Speed. */
  USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed);
 
  /* Reset Device. */
  USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
}

This part of code is in usbd_conf.c . The problem disappeared after this correction.

Hello @Peerless​ ,

Thanks for reported the problem with solution. This is raised internally for check and analysis.

Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee

Hello @Peerless​ ,

After check, this issue is already passed along to our development team for fix in the coming release.

Thanks for your contribution.

Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen