STM32CubeMX v4.21 _Error_Handler definition issues in main.h
Posted on June 08, 2017 at 02:02
Hi ST,
There are a couple issues with the definition of _Error_Handler() in main.h as generated in v4.21.0.
First of all it needs to be wrapped as follows so it can be included in both .c and .cpp files with the correct linkage:
#ifdef __cplusplus
extern "C" {
#endif
void _Error_Handler(char *, int);
#ifdef __cplusplus
}
#endif
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)BTW, this should be done for all function definitions in all header files so they work correctly in both .c and .cpp files. I'm sure there are other cases. This is just the one I've run into.
Secondly, the _Error_Handler function is defined as taking a char * for the first argument. However, in gcc __FILE__ is a const char *, so in the macro in the header:
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)an error is generated. It should be:
void _Error_Handler(const char *, int);Thanks,
Craig