cancel
Showing results for 
Search instead for 
Did you mean: 

Bug report: STM32CubeMX for STM32G051K8TX usart code generation.

MuratUnal
Associate II

Hello Everyone,

I was trying to communicate my board with a device over USART module. My MCU is STM32G051K8TX. But I hadn't been succeed until I notice a STM32CubeMX bug. Let me show you:

I used alternate function of PA9, and PA10 for USART_TX and USART_RX from STM32CubeMX. When I generate code, it prepares HAL_UART_MspInit code without alternate function of the USART pins. I intert extra code inside the /* USER CODE BEGIN USART1_MspInit 1 */ and /* USER CODE END USART1_MspInit 1 */ tags. It reinitialize the PA9, PA10 as alternate fuction USART.

You can see the code below:

/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  if(huart->Instance==USART1)
  {
  /* USER CODE BEGIN USART1_MspInit 0 */
 
  /* USER CODE END USART1_MspInit 0 */
  /** Initializes the peripherals clocks
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
    PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Peripheral clock enable */
    __HAL_RCC_USART1_CLK_ENABLE();
 
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**USART1 GPIO Configuration
    PA9     ------> USART1_TX
    PA10     ------> USART1_RX
    */
    GPIO_InitStruct.Pin = RS232_TXD1_Pin|RS232_RXD1_Pin;
    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 */
    HAL_NVIC_DisableIRQ(USART1_IRQn);
    GPIO_InitStruct.Pin = RS232_TXD1_Pin|RS232_RXD1_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    HAL_NVIC_EnableIRQ(USART1_IRQn);
  /* USER CODE END USART1_MspInit 1 */
  }
 
}

Best regards,

Murat UNAL

1 ACCEPTED SOLUTION

Accepted Solutions
Sara BEN HADJ YAHYA
ST Employee

Hello @MuratUnal​ and @TDK​ 

Thanks for your feedback,

This is a know issue and it is already raised internally to be fixed as soon as possible.

A similar issue was reported in this thread.

I will keep you posted with the updates.

If your 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 :)

Sara.

View solution in original post

3 REPLIES 3
TDK
Guru

> GPIO_InitStruct.Alternate = GPIO_AF1_USART1;

It appears this line is missing from the CubeMX generated code. It's a common bug seen on many different chips and something the CubeMX folks should do better at fixing.

@Sara BEN HADJ YAHYA​ 

If you feel a post has answered your question, please click "Accept as Solution".
Sara BEN HADJ YAHYA
ST Employee

Hello @MuratUnal​ and @TDK​ 

Thanks for your feedback,

This is a know issue and it is already raised internally to be fixed as soon as possible.

A similar issue was reported in this thread.

I will keep you posted with the updates.

If your 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 :)

Sara.

Sara BEN HADJ YAHYA
ST Employee

Hello @MuratUnal​ , @TDK​ ,

This issue is fixed in STM32CubeMX latest release.

V6.6.0 is now available under this Link.

Thanks for your contribution.

Sara.