Upgrading from 5.2.0 to 6.0.0 breaks sprintf

dajar wrote on Wednesday, October 28, 2009:

I decided to make the upgrade to FreeRTOS 6.0.0 from FreeRTOS 5.2.0. I have been using sprintf to display floating point values to the serial port. Changing to 6.0.0 I cannot get sprintf to display anything other than zero. The format string works properly, but I only see zeros on the display.

With 5.2.0 I had to play around with stack sizes to get sprintf to work properly, and to make the stack smaller, only one task, the serial port gatekeeper task, is allowed to use sprintf. With 6.0.0, adjusting the stack size makes no difference in the output. I get no error messages from sprintf.

The only difference between the working and the non-working versions are the versions of FreeRTOS. Everything else is the same.

Anybody have any suggestions? (besides "Don’t use sprintf.")

CPU is STM32F103 (Cortex-M3)
Board is custom.

anonymous wrote on Wednesday, October 28, 2009:

Which libc are you using?

rtel wrote on Wednesday, October 28, 2009:

One of the differences between V5.x.x and V6.x.x is the stack byte alignment used on ARM ports.  Previously it was set to 4 as this was good enough for everything except some operations on 8 byte data types (like using %f with sprintf).  Now it is set to 8 and all 8 byte data type problems should be fixed (?) so it is odd that you report it working before but not now.

Can you look at the stack pointer in the debugger and check that it is indeed 8 byte aligned.

Also, do you have stack overflow detection turned on?  Maybe you are simply overflowing a stack.

You could try setting portBYTE_ALIGNMENT to 4 (its old value) in portmacro.h to see if that makes it work again.  As 8 is a multiple of 4 I would not have thought it would make any difference, unless I have made a mistake somewhere else.


dajar wrote on Wednesday, October 28, 2009:

Samuel, I am using newlib.

I had forgotten to mention that I had changed the stack alignment in 5.2.0 to 8

Stack overflow detection is enabled and no stacks are overflowing.

The stack pointer value I looked at is 0x200027B4, which looks like a 4 byte aligned address. I will dig into this.


dajar wrote on Thursday, October 29, 2009:

I set a break point on the sprintf line that writes a floating point value. GDB reports that the SP = 0x20002794.

At the start of the program I printed these values:




rtel wrote on Friday, October 30, 2009:

Could you try setting a break point on the very first line of the task that calls sprintf().  Depending on the debugger being used that will often be on the opening bracket of the function.  For example:

void vATaskFunction( void *pv )
{ /* Place break point here, before variable definitions. */
int x, y, etc;

Alternatively view the code in assembly, and add a break point on the first assembly line.  The important thing is that the break point is hit before the function prologue that sets up the stack and frame pointers is executed.

What is the stack pointer value when that break point is hit?

Which compiler are you using?


rtel wrote on Friday, October 30, 2009:

Hi again.  It looks like I might have messed up because of the ‘decrement before’ behaviour.  I would be grateful if you could try the following:

<li> Open up port.c from the Source/portable//CM3 directory.
<li> Add the line "pxTopOfStack-;" to the top of the function pxPortInitialiseStack().

Let me know if that fixes the problem.

Thanks and regards.

rtel wrote on Friday, October 30, 2009:

Using markdown syntax in the reply is fine when viewed in the preview window, but does not work when viewed in the forum or in the emails of posts I received.  This forum seems totally screwy at the moment.


dajar wrote on Friday, October 30, 2009:


The stack pointer at the beginning of the function, before any other operations occur is 0x200027AC.

I put the "pxTopOfStack-;" as the first line of code in pxPortInitialiseStack() and now it is working.

Thank You!!!!

wfrancis wrote on Saturday, November 07, 2009:

Where exactly should the “pxTopOfStack-;” be put?
I checked the code in pxPortInitialiseStack, but in different versions they are the same?

rtel wrote on Saturday, November 07, 2009:

As already said - the first line in the function.  Code in that function has not changed, but code elsewhere has.