2021-10-18 05:13 AM
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.
Solved! Go to Solution.
2022-06-29 07:47 AM
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.
2021-10-18 06:03 AM
Definitely a bug. Might be useful to say what version of CubeMX you're using, and include your IOC file if you can.
2021-10-18 06:10 AM
2021-12-30 12:35 AM
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.
2022-06-29 07:47 AM
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.