3 years, 10 months ago.

mbed with stm32cubemx, HAL_TIM_MspPostInit, multiply defined or undefined symbol

I am trying to use some code generated by cubemx when I use the init code generated in mbed main I get an undefined symbol for void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

This is declared at the top of the generated cubemx main.c file and is called by one of the inits but is implemented in stm32f7xx_hal_msp.c . There isn't an include for this file in cubemx main. When I try to do the same in mbed main I get an undefined symbol. When I add an include for stm32f7xx_hal_msp.c I get a multiply defined error.

How do I use void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); ?

1 Answer

3 years, 10 months ago.

Hello David,
I'm not sure that it will solve the issue but when declaring the function in the mbed's main.cpp file try to indicate that it's a C type function in order to prevent name mangling as follows:

extern "C"  void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

Oherwise, since it's declared in a .cpp file, the C++ compiler would apply name mangling (modify the function's name before compilation) and won't find such function in the stm32f7xx_hal_msp.c file.

Accepted Answer

Thanks Zoltan, I think that might actually work, it certainly clears that error. I am still left with one error. The cubemx generated file stm32f7xx_hal_msp.c also has a declaration extern void Error_Handler(void); . I have void Error_Handler(void); declared and implemented in main.cpp but I get the compiler message Error: Undefined symbol Error_Handler (referred from stm32f7xx_hal_msp.NUCLEO_F767ZI.o). How do I declare/implement so that it satisfies the extern void Error_Handler(void); in stm32f7xx_hal_msp.c ?

posted by David Fisher 24 Mar 2017

You can try to define the Error_Handler function in the main.cpp as follows:

main.cpp

#include "mbed.h"

...

extern "C" {
    void Error_Handler(void)
    {
        printf("Error Handler called!\r\n");
        while(1) {}
    }
}

...

int main(void)
{

...

}
posted by Zoltan Hudak 24 Mar 2017

Thanks again Zoltan, that solves that error and my program now compiles and seems to be working.

posted by David Fisher 25 Mar 2017