cancel
Showing results for 
Search instead for 
Did you mean: 

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

Posted on October 12, 2016 at 22:51

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
10 REPLIES 10
Nesrine M_O
Lead II
Posted on October 13, 2016 at 12:52

Hi Andrei,

Thanks for the suggestion! I will forward this to our team. 

-Syrine-

Posted on February 16, 2017 at 00:40

I was wondering if anything came of this?

The other day I was bringing up a new board and one of my CAN busses wouldn't come up. All I could get out of Error_Handler was a generic error message which wasn't useful since there was no context.

If Error_Handler was implemented as a macro, I could have got the information out of __FILE__ and __LINE__ and that would have helped locate the issue rather than having to drop the program into debug.

Thanks.

Rob.Riggs
Senior
Posted on February 16, 2017 at 04:23

I have my own error handler that goes into a loop flashing a two-digit code in Morse code on an LED.  It has helped me nail down a number of issues without having to break out the debugger.  The numbers in Morse are easy to decode.  I typically use the first digit to represent a subsystem or thread, and the other to represent a location.

Posted on February 16, 2017 at 08:18

Exactly, I wrote my own too. Mine prints out messages on UART3 and logs to FLASH. But that is if the processor makes it to my application code. 

While the processor is booting, it executes the startup code that Cube generates. If anything goes wrong in these routines, it calls Error_Handler() with no parameters. There are quite a few calls, all the same, with no way to differentiate who has the problem.

Unfortunately Error_Handler is declared in the header files for each of the interface routines as extern void Error_Handler( void); So there isn't a clean way to override it as a macro. And since none of the interface routines give any sort of parameter, there isn't even a chance to override the void parameter and use the parameter.

Sigh, so close, but not very useful.

Jeanne Joly
Senior III
Posted on May 09, 2017 at 10:29

Hello

Chichak.Andrei

,

Your issue is now fixed and will be delivered in CubeMX 4.21 that will come very soon!

Please upgrade your CubeMX release as soon as it is available.

BR. Eric

Posted on May 30, 2017 at 19:41

Also, the USER CODE BEGIN and USER CODE END comments have an incorrect function name.

Andrei

Posted on January 22, 2018 at 17:47

Sorry

Chichak.Andrei

for my late reply.

Could you please be more precise regarding your last comment. What do you mean by the USER CODE BEGIN and USER CODE END comments have an incorrect function name? in which file do you see that point?

BR. Jeanne

Posted on January 22, 2018 at 21:13

Sure, the question was asked about 1.5 years ago, but let's see what I can do...

void

_Error_Handler(

char

* file,

int

line)

{

 

/* USER CODE BEGIN Error_Handler_Debug */

 

/* User can add his own implementation to report the HAL error return state */

 

while

(

1

)

 

{

 

}

 

/* USER CODE END Error_Handler_Debug */

}

s/Error_Handler_Debug/Error_Handler/g

Posted on January 22, 2018 at 21:32

/* User can add his own implementation to report the HAL error return state,

      or system dies a quiet death. Perhaps retry things before crawling off and dying */

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..