Skip to main content
Peerless
Associate
April 5, 2019
Question

STM32F401 USB -- USB_CoreReset failed(CSRST bit stucked)

  • April 5, 2019
  • 8 replies
  • 2018 views

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.

This topic has been closed for replies.

8 replies

ST Technical Moderator
April 5, 2019

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Peerless
PeerlessAuthor
Associate
April 6, 2019

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.

waclawek.jan
Super User
April 5, 2019

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

JW

Peerless
PeerlessAuthor
Associate
April 6, 2019

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.

waclawek.jan
Super User
April 6, 2019

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
PeerlessAuthor
Associate
April 7, 2019

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.

ST Technical Moderator
April 8, 2019

Hello @Peerless​ ,

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

Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
ST Technical Moderator
April 8, 2019

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks