Skip to main content
Associate III
August 25, 2025
Solved

STM32U5 Code Generation Bug?

  • August 25, 2025
  • 2 replies
  • 794 views

Hi,

i just generated a project using the Device Configuration Tool (1.19.0). All works. But as soon as I enable 

"Generate peripheral initialisation as a pair of '.c/.h' files per peripheral" the hardware stands at:

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
 {
////loops forever here?!?!?!
 count++;

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

 return HAL_OK;
}

 I had no closer look into what is done differently. Just wanted to report the issue. Again, if everything is inside of main.c it works!

Also wanted to note, that if using separte files it removes the last user enterable code section inside of MX_GPIO_Init(), here:

 /* USER CODE BEGIN MX_GPIO_Init_2 */

 /* USER CODE END MX_GPIO_Init_2 */
}

 Please enable!

 

Thanks,

Juergen

Best answer by Jason927

It's a bug of USB code generate.
You need to add __HAL_RCC_SYSCFG_CLK_ENABLE(); in stm32u5_hal_msp.c

void HAL_MspInit(void)
{

 /* USER CODE BEGIN MspInit 0 */
 __HAL_RCC_SYSCFG_CLK_ENABLE();
 /* USER CODE END MspInit 0 */

 __HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWREx_EnableVddUSB();
 HAL_PWREx_EnableVddIO2();
 HAL_PWREx_EnableVddA();

 /* System interrupt init*/

 /* USER CODE BEGIN MspInit 1 */

 /* USER CODE END MspInit 1 */
}




2 replies

Ghofrane GSOURI
Technical Moderator
August 25, 2025

Hello @JE_it 

Could you please provide your IOC for further investigation.

THX

GHofrane

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.
JE_itAuthor
Associate III
August 25, 2025
Jason927Best answer
Associate III
August 26, 2025

It's a bug of USB code generate.
You need to add __HAL_RCC_SYSCFG_CLK_ENABLE(); in stm32u5_hal_msp.c

void HAL_MspInit(void)
{

 /* USER CODE BEGIN MspInit 0 */
 __HAL_RCC_SYSCFG_CLK_ENABLE();
 /* USER CODE END MspInit 0 */

 __HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWREx_EnableVddUSB();
 HAL_PWREx_EnableVddIO2();
 HAL_PWREx_EnableVddA();

 /* System interrupt init*/

 /* USER CODE BEGIN MspInit 1 */

 /* USER CODE END MspInit 1 */
}




Ghofrane GSOURI
Technical Moderator
August 26, 2025

Hello @JE_it 

Could you please try adding __HAL_RCC_SYSCFG_CLK_ENABLE(); to stm32u5_hal_msp.c as suggested by @Jason927 and give me your feedback .

THX

Ghofrane

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.
JE_itAuthor
Associate III
August 26, 2025

Hi,

works!
before separating in different files the function was called twice:

grep -ri __HAL_RCC_SYSCFG_CLK_ENABLE
./Src/stm32u5xx_hal_msp.c: __HAL_RCC_SYSCFG_CLK_ENABLE();
./Src/main.c: __HAL_RCC_SYSCFG_CLK_ENABLE();

After, never. The highlighted fix by @Jason927 works.

Please fix in IDE.

Thank you,

Juergen