BriscoeTech / Arduino-FreeRTOS-SAMD21

A port of FreeRTOS that runs on Arduino Samd21 boards
64 stars 19 forks source link

Overriding FreeRTOSConfig.h #25

Open wz2b opened 3 years ago

wz2b commented 3 years ago

Hi,

Is there some way to override FreeRTOSConfig.h? I need configSUPPORT_STATIC_ALLOCATION enabled.

centerorbit commented 3 years ago

I'm also interested in this.

The board I'm using has 32kB of SRAM and it looks like configTOTAL_HEAP_SIZE is set to 14kB and I'm running out with a "Malloc Failed". Changing this line in the file directly to:

#define configTOTAL_HEAP_SIZE           ( ( size_t ) ( 25 * 1024 ) )

... fixes the build, but it'd be really nice to be able to override this without manually editing a library file.

It may very well be that a fork of this repo is needed to apply custom config. I haven't found a compiler trick that works for this yet.

drewfish commented 3 years ago

I have a custom version of this library which adds support for per-sketch configuration overrides. It's an approach that is sort-of generic, but really only works cleanly when using something like the platformio.org toolchain. Unfortunately the Arduino toolchain doesn't have a way (that I know of) for a sketch author to give #define to control how libraries are compiled.

wz2b commented 3 years ago

IIt's an approach that is sort-of generic, but really only works cleanly when using something like the platformio.org toolchain.

Mind sharing a description? I'm actually using PlatformIO. I just didn't see a great way to do this. I was thinking there needs to be a way to have local overrides maybe by manipulating the #include order (so that your local one gets found first) but I didn't really see a way.

BriscoeTech commented 3 years ago

Hello Everyone,

Overriding pre-processor commands is not available in C and C++. Also, I see anything that has to do with reordering the includes to be kinda a cludge. I want the compiler and linker to do its job and not have to meddle with the order of operations.

On the other hand I do have a recommendation. For those who are using Sloeber/Platform IO/Visual Studio Code where you have configurable project folders, I recommend version controlling a copy of the library with your project, and there you can make the appropriate changes for your project. I do this for all my Arduino Sloeber projects now, and I set the project to include the local version instead of linking to the library in the arduino libraries folder. There are alot of settings in the rtos config header, and there are alot of reason different projects may want different settings. I chose some settings that should be good enough for most people getting started, but not optimized for a specific application.

I think for anyone looking to up their arduino game, local version control of libraries is a big game changer. I have had too many projects early on that have broken because I updated a library. I had one project that needed an older version of Sdfat in order to work properly, but then a different project needed a newer version and caused me to update the library. I did not know I broke the original project until months later, and I had a heck of a time figuring out what happened. By keeping these libraries with your projects, you can customize them and grow without worry of breaking other projects

wz2b commented 3 years ago

In the NRF52480 SDK what they do a lot is have a master sdk_config.h file where every #define is surrounded by an #ifndef test, so nothing gets re-defined if it already exists.  That lets you pass in preprocessor overrides.  Since all their libraries are built from source every time that lets them override from the CFLAGS.  Not sure how/if that would work here.

I recommend version controlling a copy of the library with your project, and there you can make the appropriate changes for your project. 

That's my intended workaround. The down side is having to deal with library updates more manually.

drewfish commented 3 years ago

Here's what I did. Despite being somewhat generic I don't claim that it's a good approach :) :(

(Steps 2 and 3 are only needed since I couldn't find a way to make the preprocessor "include a file only if it exists, skip otherwise".)

With those changes (first two in each project folder, last in my shared FreeRTOS library folder) I can configure how FreeRTOS is compiled on a per-project basis.

wz2b commented 3 years ago

Yeah - ability to provide a local override for the entire file. That's less work than having to do an #ifdef around each individual setting/option. This makes me wonder, can this problem also be solved by forcing a certain cpp -I search order?

On Thu, Jan 14, 2021 at 7:27 PM Drew Folta notifications@github.com wrote:

Here's what I did. Despite being somewhat generic I don't claim that it's a good approach :) :(

  • in my platformio project, create a include/appFreeRTOSConfig.h with configuration defines (as mentioned in FreeRTOS.h)
  • in my platform.ini file, add -DAPPCONFIG_FREERTOS -Iinclude to build_flags
  • changed FreeRTOSConfig.h so that it has #ifdef APPCONFIG_FREERTOS it does a #include appFreeRTOSConfig.h

(Steps 2 and 3 are only needed since I couldn't find a way to make the preprocessor "include a file only if it exists, skip otherwise".)

With those changes (first two in each project folder, last in my shared FreeRTOS library folder) I can configure how FreeRTOS is compiled on a per-project basis.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BriscoeTech/Arduino-FreeRTOS-SAMD21/issues/25#issuecomment-760562999, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALTMOLRDG4UGJQOGGPSTHLSZ6DYDANCNFSM4UV4MRSQ .