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

CubeF0: Misleading comment - HAL_MspInit

  • July 21, 2026
  • 4 replies
  • 73 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!

4 replies

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""."
Andrew Neil
Super User
July 22, 2026

What would you suggest the message be changed to?

I think it should note that CubeMX may generate this function.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
ST Technical Moderator
July 22, 2026

Hello ​@Andrew Neil 

CubeMX-generated files are considered user files, since they include dedicated sections where you can safely add your own code.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
Andrew Neil
Super User
July 22, 2026

CubeMX-generated files are considered user files,

That may be ST’s internal take, but I don’t think most Users would see it that way.

 

since they include dedicated sections where you can safely add your own code.

On the contrary, that suggests they are not User files - because the User has to be careful to only put User code in those specially-designated places.

A “User file” should be a file created by the User, over which the User has complete control, and in which the User is completely free to do whatever they like, and wherever they like.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.