Skip to main content
ADunc.1
Senior
March 20, 2026
Solved

STM32CubeMX does not generate UART clock init

  • March 20, 2026
  • 2 replies
  • 211 views

Code generation of the attached .ioc file (copy of ST example file of similar name) does not generate clock init for UART4.  This means the example application hard faults.  I see no reason why the UART clock should not be initialised here and would save someone time debugging in the future!

In stm32mp2xx_hal.c:

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(huart->Instance==UART4)
 {
 /* USER CODE BEGIN UART4_MspInit 0 */
	// TODO: Need this here! __HAL_RCC_UART4_CLK_ENABLE();
 /* USER CODE END UART4_MspInit 0 */

 /**UART4 GPIO Configuration
 PH8 ------> UART4_RX
 PH7 ------> UART4_TX
 */
 GPIO_InitStruct.Pin = GPIO_PIN_8;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Alternate = GPIO_AF4_UART4;
 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_7;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF4_UART4;
 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

 /* USER CODE BEGIN UART4_MspInit 1 */

 /* USER CODE END UART4_MspInit 1 */

 }

}

 

Best answer by Ghofrane GSOURI

Hello ​@ADunc.1 

This issue has been fixed in the latest version of STM32CubeMX 6.18.0 

Download STM32CubeMX6.18.0 from  here 

THX

Ghofrane

2 replies

Ghofrane GSOURI
ST Technical Moderator
March 22, 2026

Hello @ADunc.1 

Your contribution is much appreciated.

Issue has been escalated to dev team under internal ticket ID #0060887

I will kee

 

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.
Ghofrane GSOURI
Ghofrane GSOURIBest answer
ST Technical Moderator
July 1, 2026

Hello ​@ADunc.1 

This issue has been fixed in the latest version of STM32CubeMX 6.18.0 

Download STM32CubeMX6.18.0 from  here 

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.