cancel
Showing results for 
Search instead for 
Did you mean: 

Request for enhancement. Error_Handler in main.c generated by Cube 4.17.0 oops 5.5.0

In the latest version of CubeMX for F4 1.24.2, the parameters on Error_Handler have disappeared. I can't find a control in the code generator page to enable it again.

What gives?

A few years ago, I wrote:

"In the latest version of Cube (4.17.0), when main.c is generated, you get a function called Error_Handler() that is called by the HAL functions anytime the return code is not HAL_OK. Error_Handler just goes into a tight loop, leaving you scratching your head as to why your program isn't working.

This is somewhat better than the previous construct, but in my small program, this function is called in 51 places. It would be useful if Error_Handler had some parameters so you could print out __FILE__ and __LINE__ so you could at least print out some sort of message that could lead you to a solution. That would mean using some sort of a macro along the lines of assert_param.

As it is now, the only thing that Error_Handler can be used for is some sort of printf(''blammo I blew up\n''); or as a space to put a breakpoint for when you are debugging.

Thanks,

Andrei from The Great White North"

3 REPLIES 3
TDK
Guru

I have the following in my code. I'm pretty sure this was done by STM32Cube and not myself, but I could be wrong. In any case, it'll give you a workaround:

void _Error_Handler(char *, int);
 
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)

Then you just need to implement _Error_Handler somewhere.

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

That is exactly what I had in my code until last version.

Yeah, there it is. It WAS in main.h until this version. It's gone now. And the implementation in main.c is back to being void Error_Handler(void)

A

Pavel A.
Evangelist III

Quick fix while developing: put a __BKPT() in your ErrorHandler().

When it hits, debugger will show call stack.

When it comes to production version, make a better handler: something like folks do in a hard fault handler: unwind stack, find the caller, and so on.

-- pa