cancel
Showing results for 
Search instead for 
Did you mean: 

UART not configured properly for STM32G061

VDomi.2
Associate

Hello,

I want to report that using the STM32CubeMX functionalities with an STM32G061 I found that configuring the USART1 using PA9 and PA10 there's an issue that prevents it to work properly.

More precisely, in the generated function HAL_UART_MspInit, the alternate function is not configured for UART 1. I paste a snipped where the UART1 and UART2 are configured:

void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(uartHandle->Instance==USART1)
  {
  /* USER CODE BEGIN USART1_MspInit 0 */
 
  /* USER CODE END USART1_MspInit 0 */
    /* USART1 clock enable */
    __HAL_RCC_USART1_CLK_ENABLE();
 
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**USART1 GPIO Configuration
    PA9     ------> USART1_TX
    PA10     ------> USART1_RX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    /* USART1 interrupt Init */
    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART1_IRQn);
  /* USER CODE BEGIN USART1_MspInit 1 */
 
  /* USER CODE END USART1_MspInit 1 */
  }
  else if(uartHandle->Instance==USART2)
  {
  /* USER CODE BEGIN USART2_MspInit 0 */
 
  /* USER CODE END USART2_MspInit 0 */
    /* USART2 clock enable */
    __HAL_RCC_USART2_CLK_ENABLE();
 
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**USART2 GPIO Configuration
    PA2     ------> USART2_TX
    PA3     ------> USART2_RX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    /* USART2 interrupt Init */
    HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART2_IRQn);
  /* USER CODE BEGIN USART2_MspInit 1 */
 
  /* USER CODE END USART2_MspInit 1 */
  }
}

As you can see, in UART2, the GPIOs alternate functions are configured properly by the line: GPIO_InitStruct.Alternate = GPIO_AF1_USART2;

This is missing for the USART1 confguration and it should include the line:

GPIO_InitStruct.Alternate = GPIO_AF1_USART1;

Edit:

As pointed out, I should have added the versions I am using. The versions are STM32CubeMX version 6.3 (actually I updated my version in case it was solved) for Linux and Firmware Package 1.5.0.

I update an .ioc that can reproduce the issue as well.

1 ACCEPTED SOLUTION

Accepted Solutions
Sara BEN HADJ YAHYA
ST Employee

Hello @Community member​ ,

This issue is fixed in STM32CubeMX latest release.

V6.6.0 is now available under this Link.

Thanks for your contribution.

Sara.

View solution in original post

4 REPLIES 4
TDK
Guru

Definitely a bug. Might be useful to say what version of CubeMX you're using, and include your IOC file if you can.

If you feel a post has answered your question, please click "Accept as Solution".

Sorry, I should have posted that info in the first message. I'm using STM32CubeMX version 6.3 (actually I updated my version in case it was solved) for Linux.

I am using Firmware Package 1.5.0.

I can't upload the original IOC file, but I have created one that behaves the same way.

Sara BEN HADJ YAHYA
ST Employee

Hello @Community member​ ,

Thanks for your feedback,

I confirm the issue and I reported it to the dev team.

If you issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly ��

Regards,

Sara.

Sara BEN HADJ YAHYA
ST Employee

Hello @Community member​ ,

This issue is fixed in STM32CubeMX latest release.

V6.6.0 is now available under this Link.

Thanks for your contribution.

Sara.