cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 Code Generation Bug?

JE
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jason927
Associate III

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 */
}




View solution in original post

6 REPLIES 6
Ghofrane GSOURI
ST Employee

Hello @JE 

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.

Sure!

Jason927
Associate III

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 */
}




Hello @JE 

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.

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 

Hello @JE @Jason927 

Thanks a lot for your contribution.

Issue has been raised to dev team for correction.

Internal ticket number is 216303 

I will keep you posted with updates.

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.