Skip to main content
Andrew Neil
Super User
July 21, 2026
Question

CubeF0: Misleading comment - HAL_MspInit

  • July 21, 2026
  • 1 reply
  • 16 views

In stm32f0xx_hal.c:

/**
* @brief Initialize the MSP.
* @retval None
*/
__weak void HAL_MspInit(void)
{
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_MspInit could be implemented in the user file
*/
}

 

But this must not be implemented in a User file, because there is already an implementation generated by CubeMX in stm32f0xx_hal_msp.c:

/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */

/* USER CODE END MspInit 0 */

__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();

/* System interrupt init*/

/* USER CODE BEGIN MspInit 1 */

/* USER CODE END MspInit 1 */
}

 

So implementing a HAL_MspInit() in a User file - as the comment in stm32f0xx_hal.c suggests - will cause a “multiple definition” Linker error!

1 reply

TDK
July 21, 2026

From the perspective of HAL, files generated by CubeMX are user files. HAL doesn’t know about CubeMX--I think it should stay that way.

What would you suggest the message be changed to?

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