2018-09-26 10:20 AM
hi all,
we're using SW4STM32 on a project that uses CubeMX-generated code with FreeRTOS. Our own application is a mix of C and C++. We soon found that malloc/free (used behind the scenes by C++) don't play nice in the multi-threaded environment.
Dave Nadler's solution for overriding FreeRTOS memory management with newlib's [http://www.nadler.com/embedded/newlibAndFreeRTOS.html] works as far as we've tested it ...
... but is there no ready-made already integrated solution?
Thank you for your consideration,
-Dan
2018-09-26 06:55 PM
With embedded C++, the preferred options are:
Are any of these an option for you?
The problem with 2 & 3 is that with C++ you need to enable exception handling in order to properly handle and detect out-of-memory conditions for containers. std::vector, for example, can only indicate that an allocation failed by throwing std::bad_alloc.
2018-09-27 06:45 AM
There are ready, integrated solutions for C++. They are called Linux, VxWorks and so on.
If you don't have enough RAM - simply don't use C++. C11 is good enough for very small systems.
The fun of C++ is in using the power stuff freely. Otherwise fun is out and pain in.
Enjoy the holiday!
-- pa
2018-09-27 07:44 AM
Thanks for the quick reply, Rob.
Yes, those are all options for us.
Maybe I should've mentioned that the problem (newlib and FreeRTOS interaction) first came to light trying to "printf" from several threads (mix of C and C++) at once ... then we realized it was a bigger problem.
2019-08-07 07:23 AM
@Community memberharon - Please note I've just posted updated details for STM here:
http://www.nadler.com/embedded/newlibAndFreeRTOS.html
We use C++ heavily, with the caveats suggested by @Rob.Riggs above.
Hope that helps!
Best Regards, Dave
2019-08-07 08:50 AM
Thanks very much, Dave. We basically adapted your original solution much as you just did for STM. It's been happily running for months and months. It was great help, and much appreciated.
Cheers,
-Dan
2020-06-21 04:36 AM
Hi Dave,
I am interested in you solution, but unfortnutaly this link is broken :
http://www.nadler.com/embedded/newlibAndFreeRTOS.html
Can you kindly help ?
Best Regards
Marco
2020-06-21 02:49 PM
Yep, link busted....
The time machine to the rescue!
https://web.archive.org/web/20191122000347/http://www.nadler.com/embedded/newlibAndFreeRTOS.html
-- pa
2020-06-21 02:53 PM
Link is not broken, just wait a while and it loads.
alexgorbatchov's syntax-highliter scripts are not loading, but the main page loads after getting 522 errors on the scripts.
Aaarrrggg...
I'll try fix it in the next few days.