FreeRtos LPC2368 and newlib sprintf

pfav63 wrote on Sunday, August 31, 2008:

Hi guys

I´m trying to use floating point on FreeRtos / LPC2368 / newlib environment !
Yes I know, float and small uC w/o hw-math is not the best, but is good enough to quickly start some tests.

I’m able to run math functions like sin, cos, …, but the system fails on sprintf( " … %f ").

I dig the network and I get confused about newlib and reentrancy!
At this time I don’t need functions like write_r …, to interface printf to UART, I’d like to get a formatted string.

Is anyone using sprintf with float data?

my gcc env:
gcc 4.2.1
newlib  1.15.0
FreeRtos 5.0.2



jmr1972 wrote on Monday, September 01, 2008:


Not sure if it’s the same as on other micros but you may need to pass the following options to the linker to include the floating point version of vfprintf (called by printf)

-Wl,-u,vfprintf -lprintf_flt

Hope this helps.

pfav63 wrote on Monday, September 01, 2008:

Thanks JMR, but it does not solve my problem.

I’m using newlib-1.15 w/o syscall.x for LPC2368: freeRTOS demo is working fine (HTTPserver task is using sprintf).
I add a new task to handle the UART, then I use sprintf to format a string before ask uart to send it: the system start to fail after a while, so I have reentrancy problems.
I stop the HTTPserver task and the system is fine until I add a %f  on sprintf: if floatval is 0.0 all is fine, otherwise it crash.

I rebuilt the newlib using  "–enable-newlib-multithread=yes" (configure phase). Nothing is changed. Compilation and link are fine: no missed references (I was waiting for at least one …_r function missing)

I’m lost!

-  looking the configure shell it seems that --enable-newlib-multithread=yes is already a default value and newlib package provide a dummy stubs for all syscall needed. Is it true?
- newlib heap: which one? The one provided by C (I have to set someting in boot.s?) or provide a wrap to freeRtos heap?
- _r functions:  which are mandatory ?
- In which way I have to force the activation of the reentrancy?



rtel wrote on Monday, September 01, 2008:

Some of the demos reduce the code size by including a file called printf-stdarg.c in the project to provide the sprintf functionality.  This is a very cut down version and does not include floating point formatting.  Does your project include this file?  If it does, try removing it.


pfav63 wrote on Monday, September 01, 2008:

Thanks Richard,
no, my prj does not include this file.


damienhoyen wrote on Wednesday, September 03, 2008:


Are you using Yagarto ? If yes,

I had exactly the same problem
Look thread here:

It’s simple, the support for float HAVE NOT BEEN included on the Newlib printf and all the family (sprint, vsprintf…)
(at least with the yagarto precompiled)…

You will have to recompile a new lib (good luck)…

Best way: Multiply your float by 1 000 or 1 000 000  (according to your application and the acceptable error)  and use an integer to store your float, will be better for calcul letter.

For the printf of this number, use a function like the example here,
at the end…



pfav63 wrote on Wednesday, September 03, 2008:

hi Damien,

thanks for the info.

I built my own GCC toolchain using ubuntu:
binutil 2.17
GCC 4.2.1
newlib 1.15
gdb 6.6

Compiling newlib I found a problem detecting the makeinfo version, so the build fail. I solve it modifying the newlib config shell.

I’m in trouble to find docs about newlib’s configuration switch, but digging internet I’m trying to collect as much is possible.

Now I’m working to check if new lib and freeRTOS are integreted in the right way.

Agree with your suggestions about floating point!