# FreeRtos LPC2368 and newlib sprintf

**URL:** <https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015>\
**Category:** Kernel\
**Created:** [August 31, 2008, 1:43pm UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015 "2008-08-31T13:43:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 31, 2008, 1:43pm UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/1 "2008-08-31T13:43:27Z")

</div>

**[pfav63](https://sourceforge.net/u/pfav63/)** wrote on [Sunday, August 31, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75):

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&nbsp; 1.15.0  
FreeRtos 5.0.2

regards

P.

---

<div class="post-metadata">

**Author:** ![SergentSloGin](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/sergentslogin/32/48_2.png) [@SergentSloGin](https://forums.freertos.org/u/SergentSloGin)\
**Post date:** [September 1, 2008, 10:56am UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/2 "2008-09-01T10:56:46Z")

</div>

**[jmr1972](https://sourceforge.net/u/jmr1972/)** wrote on [Monday, September 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75/f93b):

Hi,

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 1, 2008, 9:30pm UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/3 "2008-09-01T21:30:22Z")

</div>

**[pfav63](https://sourceforge.net/u/pfav63/)** wrote on [Monday, September 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75/f93b/a915):

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&nbsp; on sprintf: if floatval is 0.0 all is fine, otherwise it crash.

I rebuilt the newlib using&nbsp; "–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!

Now  
-&nbsp; 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:&nbsp; which are mandatory ?  
- In which way I have to force the activation of the reentrancy?

thanks

P.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 1, 2008, 9:42pm UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/4 "2008-09-01T21:42:24Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, September 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75/f93b/a915/58f7):

Some of the [FreeRTOS.org](http://FreeRTOS.org) demos reduce the code size by including a file called printf-stdarg.c in the project to provide the sprintf functionality.&nbsp; This is a very cut down version and does not include floating point formatting.&nbsp; Does your project include this file?&nbsp; If it does, try removing it.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 1, 2008, 9:47pm UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/5 "2008-09-01T21:47:38Z")

</div>

**[pfav63](https://sourceforge.net/u/pfav63/)** wrote on [Monday, September 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75/cef5):

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

P.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 3, 2008, 8:45am UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/6 "2008-09-03T08:45:28Z")

</div>

**[damienhoyen](https://sourceforge.net/u/damienhoyen/)** wrote on [Wednesday, September 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75/b895):

Hi,

Are you using Yagarto ? If yes,

I had exactly the same problem  
Look thread here: [http://en.mikrocontroller.net/topic/157554#new](http://en.mikrocontroller.net/topic/157554#new)

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&nbsp; (according to your application and the acceptable error)&nbsp; 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…  
[http://en.mikrocontroller.net/topic/160785#new](http://en.mikrocontroller.net/topic/160785#new)

Regards.

Damien

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 3, 2008, 9:19am UTC](https://forums.freertos.org/t/freertos-lpc2368-and-newlib-sprintf/3015/7 "2008-09-03T09:19:46Z")

</div>

**[pfav63](https://sourceforge.net/u/pfav63/)** wrote on [Wednesday, September 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/857f4154/#8e75/8d90):

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!

regards

Paolo&nbsp;
