2019-04-05 06:35 AM
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.
2019-04-05 07:17 AM
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
2019-04-05 07:27 AM
You probably don't have set up a proper 48MHz clock, or have it set/enabled late.
JW
2019-04-06 05:38 AM
2019-04-06 05:44 AM
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.
2019-04-06 09:50 AM
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
2019-04-07 07:12 AM
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.
2019-04-08 05:29 AM
Hello @Peerless ,
Thanks for reported the problem with solution. This is raised internally for check and analysis.
Regards,
Imen
2019-04-08 07:22 AM
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