2023-12-12 06:18 AM
I am working on a project using USB HS with:
STM32U595VJT
STM32CubeIDE 1.14.0
STM32Cube_FW_U5_V1.4.0
Using the init code, as generated by CubeMX, I was getting HAL_TIMEOUT returned by USB_CoreReset():
MX_USB_OTG_HS_PCD_Init() -> HAL_PCD_Init() -> USB_CoreInit() -> USB_CoreReset()
After looking into example applications, e.g.:
STM32Cube_FW_U5_V1.4.0/Projects/NUCLEO-U5A5ZJ-Q/Applications/USBX/Ux_Device_CDC_ACM/Core/Src/stm32u5xx_hal_msp.c
the problem turns out to be a missing call to:
__HAL_RCC_SYSCFG_CLK_ENABLE();
CubeMX code does not generate it.
The application example has it in the "USER CODE" section:
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hpcd->Instance==USB_OTG_HS)
{
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* USER CODE END USB_OTG_HS_MspInit 0 */
This seems to be specific to chips with USB HS (U595, U599, U5A5, U5A9).
As the USB is not usable without it, can this missing call be added to output code generated by CubeMX?
Thank you.
Solved! Go to Solution.
2024-07-08 02:42 AM - edited 2024-07-08 02:43 AM
Hello,
@Lukasz Nowak The issue is fixed in STM32CubeIDE1.16.0 and STM32Cube MX 6.12.0 versions.
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hpcd->Instance==USB_OTG_HS)
{
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* USER CODE END USB_OTG_HS_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USBPHY;
PeriphClkInit.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_HSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
@Raees Could you please try with the last version of STM32CubeMx and let me know if the issue is solved.
I have noted that __HAL_RCC_SYSCFG_CLK_ENABLE(); has been included stm32f7xx_hal_msp.c file.
Please take a look at these examples may help you STM32CubeF7/Projects/STM32F722ZE-Nucleo/Applications/USB_Device at master · STMicroelectronics/STM32CubeF7 · GitHub
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-12 06:46 AM - edited 2023-12-12 06:52 AM
Hello @Lukasz Nowak ,
Thank you for sharing this issue.
I confirm the issue and it has already been reported internally.
Internal ticket number: 157784 (This is an internal tracking number and is not accessible or usable by customers).
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-05-22 03:42 PM
Hello,
Getting the same issue with an STM32F722RET. HAL_TIMEOUT returned by USB_CoreReset():
But at the same time, USB_OTG_FS init is working and there is no time-out.
Any solution or workaround for this issue?
2024-07-08 02:42 AM - edited 2024-07-08 02:43 AM
Hello,
@Lukasz Nowak The issue is fixed in STM32CubeIDE1.16.0 and STM32Cube MX 6.12.0 versions.
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hpcd->Instance==USB_OTG_HS)
{
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* USER CODE END USB_OTG_HS_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USBPHY;
PeriphClkInit.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_HSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
@Raees Could you please try with the last version of STM32CubeMx and let me know if the issue is solved.
I have noted that __HAL_RCC_SYSCFG_CLK_ENABLE(); has been included stm32f7xx_hal_msp.c file.
Please take a look at these examples may help you STM32CubeF7/Projects/STM32F722ZE-Nucleo/Applications/USB_Device at master · STMicroelectronics/STM32CubeF7 · GitHub
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-07-09 03:16 AM
Hi @Raees ,
I think you're facing a different issue than the one originally reported in the initial thread.
For that I recommend you to create a dedicate post for the new issue.
Also, I advise you to share your .ioc file for checking.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-07-09 03:46 PM
Hi @KDJEM.1
I can confirm that the code generated by STM32CubeIDE 1.16.0 for STM32U595 is correct now. The missing line has been added.
While trying to test it, I still had USB_CoreReset() failing to exit. It was looping here:
do
{
count++;
if (count > HAL_USB_TIMEOUT)
{
return HAL_TIMEOUT;
}
} while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_CSRST) == USB_OTG_GRSTCTL_CSRST);
The USB_OTG_GRSTCTL_CSRST was not getting cleared.
I was able to fix it by switching OTG HS Clock Mux from HSE / 2 (my crystal is 32 MHz) to PLL1P:
System Clock Mux is set to PLLCLK, PLL1 Source Mux is HSE.
With PLL1P, USB_CoreReset() returns successfully. With HSE / 2 - it does not.
If I switch OTG PHY ref clock to 32 MHz and use HSE as source, it also works correctly. So the problem appears to be with the HSE / 2 setting only.
I am not sure if you want to track it here. The original problem, with the missing __HAL_RCC_SYSCFG_CLK_ENABLE() is fixed.
2024-07-10 02:22 AM
Hi @Lukasz Nowak ,
Thank you for confirming that the original issue has been fixed in STM32CubeIDE1.16.0 version.
To give more visibility, I recommend you to create a dedicate thread for this new issue.
Thank you for your contribution in STCommunity.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-12-02 12:30 PM
I can confirm that CubeMX 6.12.0 most definitely does not generate this line, cannot comment on 6.13.0. The examples also put it within the user code section. I believe this function call should be generated automatically, so the issue is definitely not fixed.
2024-12-02 11:11 PM
Hello @marcsekz,
Could you please create a new thread indicating which STM32 you used.
Are you used "Generate peripheral initialization as a pair of '.c/.h' files per peripheral" feature?
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.