CH_CFG_SYSTEM_HALT_HOOK compilation errors

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
jayalfredprufrock
Posts: 36
Joined: Tue Jan 13, 2015 6:33 am
Has thanked: 8 times

CH_CFG_SYSTEM_HALT_HOOK compilation errors

Post by jayalfredprufrock »

GCC outputs a million errors when I try to add some logging code to the CH_CFG_SYSTEM_HALT_HOOK definition within chconf.h. I have a standalone logging header file that I #include at the top of chconf.h that includes board.h, stm32f4xx.h, a few standard lib headers, and a few definitions for reading/writing to the RTC backup registers. The errors are generally of the form "bad instruction" or "junk at end of line". Does the way chibios get compiled in the makefile prevent including any standard libraries within chconf.h? I feel like I must be doing something wrong since the hooks don't seem very useful if I can't have access to at least some super basic functions.
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Has thanked: 15 times
Been thanked: 24 times

Re: CH_CFG_SYSTEM_HALT_HOOK compilation errors

Post by Thargon »

Hi,

I would recommend to put your code in an external function and just add the according call to the hook:

Code: Select all

#define CH_CFG_SYSTEM_HALT_HOOK(reason) {                                   \
  _Pragma("GCC diagnostic ignored \"-Wimplicit-function-declaration\"" )    \
  logHaltError(reason);                                                     \
  _Pragma("GCC diagnostic pop")                                             \
}

If you then define logHaltError() in another .c file, you omit all the messy things that can happen with macros and don't have to include your dependencies in chconf.h. Maybe that helps you to find the root of your issue, just give it a try ;)
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: CH_CFG_SYSTEM_HALT_HOOK compilation errors

Post by Giovanni »

You may also put the function prototype in the hook before calling it, no need for pragmas.

Anyway, I agree that it is better to simply call a function from hooks, less risks (it is a macro surrounded by critical code).

Giovanni
Post Reply