cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX v4.21 _Error_Handler definition issues in main.h

Craig B
Associate II

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

10 REPLIES 10

You can see my fix for this above and below this post. It undoes the parameter removal introduced in the new revision. For some reason, ST seems to think removing the ability to report the code location is a 'feature' and doesn't plan to fix it.