Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Small libc for embedded systems [closed]

Tags:

I am looking for a small libc for embedded use with freertos on a ARM7 microcontroller. I have looked at newlib, but it is a bit too complex for my needs. Newlib calls malloc() in a number of functions (e.g. printf()), which is not good for small embedded realtime systems.

Does anyone know of a small, portable, open source libc implementation that will fit my application?

like image 377
GT. Avatar asked Feb 07 '11 12:02

GT.


4 Answers

PDCLib might fit your needs. It's still incomplete [broken link], though, and probably in need of a lot more real-world testing. Its author goes by DevSolar here on SO.

update 2012-11-01: As of 2012-08-14, development has been taken over by Owen Shepherd, complete with a new homepage and bitbucket repository [broken link, use this one].

update 2015-10-31: The dedicated website seems to be dead, but the code can still be found on bitbucket. The last commit to that repository happened 2014-11-24.

update 2016-07-12: The website is back up, and DevSolar started committing again on 2016-03-01.

like image 166
Christoph Avatar answered Oct 13 '22 02:10

Christoph


I use newlib on my Cortex_M3 with 32kB RAM, and to eliminate the malloc() you can use siprintf() or sniprintf().

Pro: No more calls to malloc().

Con: It does not suport formatting float and double, and is not really portable this way.

like image 39
Turbo J Avatar answered Oct 13 '22 03:10

Turbo J


If you use newlib and do not implement the sbrk syscall, then any function you use that requires malloc will generate a linker error, which will prevent you from inadvertently using a call that requires dynamic memory . So I would suggest that you do that, and then simply avoid those functions that cause the linker error. You can modify or override any library functions you do not wish to use.

like image 38
Clifford Avatar answered Oct 13 '22 02:10

Clifford


printf() is not good for small embedded realtime systems!

Actually it is worse than malloc in many ways. Variable argument lists, very complex formatting, float number support when you don't need it etc etc. printf() comes with an enormous overhead, and the compiler will not be able to reduce it, as every parameter passed to it is evaluated in runtime.

printf() is perhaps ok for hobbyists and beginners still learning C. But if you are a professional programmer, you really ought to write your own serial monitor / LCD routines. You will dramatically improve the program performance and flash consumption.

like image 39
Lundin Avatar answered Oct 13 '22 03:10

Lundin