CH_CFG_SYSTEM_HALT_HOOK compilation errors

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

CH_CFG_SYSTEM_HALT_HOOK compilation errors

Postby jayalfredprufrock » Thu Aug 17, 2017 6:31 am

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
Location: CITEC, Bielefeld University, germany
Has thanked: 15 times
Been thanked: 24 times
Contact:

Re: CH_CFG_SYSTEM_HALT_HOOK compilation errors

Postby Thargon » Tue Oct 10, 2017 9:55 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: CH_CFG_SYSTEM_HALT_HOOK compilation errors

Postby Giovanni » Tue Oct 10, 2017 10:12 am

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


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 11 guests