How to split halconf.h?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

ceremcem
Posts: 59
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 6 times
Been thanked: 3 times

How to split halconf.h?

Postby ceremcem » Wed Jun 19, 2019 2:18 pm

I prefer not to alter the default lines (eg. from "FALSE" to "TRUE"):

Code: Select all

/**
 * @brief   Enables the PWM subsystem.
 */
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM                         FALSE
#endif



...but overwrite them at the beginning of "halconf.h":


Code: Select all


// ---------- Overwrites ----------
#define HAL_USE_PWM                         TRUE
// ---------------------------------------------------

/**
 * @brief   Enables the PWM subsystem.
 */
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM                         FALSE
#endif


That works correctly.

However, if I write my overrides in another file (halconf_overrides.h) and include it halconf.h:

Code: Select all

... (halconf.h beginning)

#include "halconf_overrides.h"

...



... it throws compilation errors:

Code: Select all

/home/aea/sw2/include/ramp.c:21: undefined reference to `pwmStart'
/home/aea/sw2/include/ramp.c:22: undefined reference to `pwmEnableChannel'
/home/aea/sw2/include/ramp.c:29: undefined reference to `pwmChangePeriod'
/home/aea/sw2/include/ramp.c:30: undefined reference to `pwmEnableChannel'
/home/aea/sw2/include/ramp.c:34: undefined reference to `pwmStop'
/home/aea/sw2/include/ramp.c:38: undefined reference to `PWMD1'
/tmp/ccilWRV1.ltrans10.ltrans.o: In function `halInit':
/home/aea/ChibiOS/os/hal/src/hal.c:102: undefined reference to `pwmInit'
collect2: error: ld returned 1 exit status
/home/aea/ChibiOS/os/common/startup/ARMCMx/compilers/GCC/rules.mk:261: recipe for target 'build/ch.elf' failed
make: *** [build/ch.elf] Error 1


I'm sure that my "halconf_overrides.h" is included because when I add "#error hello world", "make" throws this "hello world" error.

What is the correct way to split this file?

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: How to split halconf.h?

Postby Giovanni » Wed Jun 19, 2019 2:23 pm

Hi,

That file is meant to be edited, it is a configuration file.

Giovanni

ceremcem
Posts: 59
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 6 times
Been thanked: 3 times

Re: How to split halconf.h?

Postby ceremcem » Wed Jun 19, 2019 7:39 pm

Giovanni wrote:Hi,

That file is meant to be edited, it is a configuration file.

Giovanni


I'm trying to simplify reading and the upgrade process of application specific configuration by separating overrides from the rest of default configuration. That's why I don't want to modify the configurations in place, but override them by declaring them separately on top of the header file.

Now my current configuration files look like this:

Code: Select all

#ifndef HALCONF_H
#define HALCONF_H

#define _CHIBIOS_HAL_CONF_
#define _CHIBIOS_HAL_CONF_VER_6_0_

#include "mcuconf.h"

/*===========================================================================*/
// Overrides

#define PAL_USE_CALLBACKS                   TRUE
#define HAL_USE_PWM                         TRUE
#define HAL_USE_SPI                         TRUE

// End of overrides
/*===========================================================================*/


/**
 * @brief   Enables the PAL subsystem.
 */
#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
#define HAL_USE_PAL                         TRUE
#endif

....

#endif /* HALCONF_H */

/** @} */



In this way, I can easily read the application configuration by looking at the section between "Overrides" and "End of overrides". Moreover, when I need to upgrade ChibiOS version, I'll easily know what subsystem to enable.

At this point, I want to take this approach one step further: If I won't touch the default configuration, why should I carry them in the same file? IMO, if they are separated into a different file (like "halconf_defaults.h"), it will be more like a "Multi-select dropdown" where the available options are listed in halconf_defaults.h and only enabled subsystems are listed in halconf.h.

Do we agree that this approach is useful?

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: How to split halconf.h?

Postby Giovanni » Wed Jun 19, 2019 7:49 pm

Halconf.h is an editable file, you can implement your defaults in there, no problems in doing so.

Giovanni

ceremcem
Posts: 59
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 6 times
Been thanked: 3 times

Re: How to split halconf.h?

Postby ceremcem » Wed Jun 19, 2019 8:14 pm

It seems that we are having a tiny communication issue here. Let me explain my proposal:

Current Status

1. I'm using Chibi-project which is the command line alternative to the Chibi-Studio.
2. I'm copying the default halconf.h into application directory into the hardware declaration folder.
3. I'm editing halconf.h in place and enabling the subsystems according to my needs.

There is no problem till this point.

The improvement

Goals:

1. Read the enabled subsystems by looking at "halconf.h" much more easily.
2. Upgrade the halconf.h when a major ChibiOS version upgrade is being applied.

Proposal:

In order to achieve these goals, halconf.h shouldn't be edited in place, but the enabled subsystems should be overridden by separately defined macros. (See my previous post).

In order to make directory structure more cleaner, I thought I can move current "halconf.h" into "/chibi-project/confdir/halconf_defaults.h" and place a "overrides file" in "/hw/for-basic-app/halconf_enabled.h".

In this way, I can open /chibi-project/confdir/halconf_defaults.h to see my available options and write to /hw/for-basic-app/halconf_enabled.h file the subsystems I want to enable.

With this approach, /hw/for-basic-app/halconf_enabled.h file becomes about 3 lines long file (instead of 500+ lines of file), thus a much more easy to manage file.

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: How to split halconf.h?

Postby Giovanni » Wed Jun 19, 2019 9:04 pm

I understood the idea, I see no problems in doing that.

If you look at chconf.h, you can see it already includes definitions guards for that kind of solution. Halconf.h does not have that, you could do just like in chconf.h.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 1 guest