Hard faults using sprintf() and float

onkel.jack@t-online.de onkel.jack@t-online.de
Mon Apr 3 18:57:00 GMT 2017

Just a hint:

I run into same problem for 2 reasons, but for a different operating system:
1. the malloc locks (using newlib malloc) did not work while I used multiple threads. this messed up the malloc chain.
2. I figured out, printf is quite hungry in respect of using stack. Depending on newlib config and version the stack usage of printf family counts up to around 1,5 Kb. So I would suggest as first check the size of your stack to have enough space to bear the need of printf. Especially in your case while printing float, this sounds shomehow familiar to me.

Good luck.

Betreff: Re: Hard faults using sprintf() and float
Datum: 2017-04-03T15:20:14+0200
Von: "Jochen Strohbeck" <jochen@strohbeck.net>
An: "newlib@sourceware.org" <newlib@sourceware.org>

The hard fault and strange formatted output does not happen if a
semaphore is used to protect sprintf().

Again, this problem seems only to happen if floats are printed and this
behaviour has been observed and reported by other users in the past and
I wonder what happens here. I have implemented malloc_r() which is using
FreeRTOS own heap4 pvPortMalloc() and is called by newlib's sprintf(),
printf(), puts() etc. So memory allocation seems not to be the real
problem here. Are there other functions to be implemented which are
called by sprintf() in order to protect it ?

In this article www.billgatliff.com/newlib.html the compile switch
configUSE_NEWLIB_REENTRANT but get an ASSERT() due to a corrupted task
descriptor in FreeRTOS if sprintf() is not guarded by my semaphore.

I downloaded and compiled newlib on Windows but it seems that the lib is
built for Intel not ARM (makefile refers to gcc not arm-none-eabi-gcc).
Any switch that must be passed to configure ?

> Can I check if the provided newlib library is ready for (Free)RTOS
> applications ?

More information about the Newlib mailing list