Ive been messing around with an annoying problem in FreeRTOS and after few hours of testing, google searching i still cant resolve my problem. I am currently developing on a LM3S6965 Ethernet Eval Board.
In my project its necessary to use float and double but i cant seem to get it right.
INT8U buffer[50];
float value = 123.45;
sprintf(buffer, "%3.2f", value);
When following code has been executed the buffer still remains 0x00 in all fields. Although normal integers does work with sprintf.
The interesting part of my config looks like following:
Many of the standard FreeRTOS demos include a tiny printf()/sprintf() implementation that is contained in a file called printf-stdarg.c. Are you including this file in your build, because it does not include floating point support. If you are including it, simply remove it to fall back to the default compiler provided library version, and then it should work (but will also take a lot more stack space to execute).
I am facing the exact same problem with my STM32F4. I am using the same settings like flashyarm. I found that this problem only occures when using the port.c for the Cortex M4F with FPU support activated. when using the M3 port ( no FPU support) it is working well. However internally the floating point calculations seem to be right, because when i cast them to int and then call printf() the values are right. Is there any solution to this?
@flashyarm could you please be so kind to share your solution with us?
Some of these problems were caused by stack alignment issues with 8 byte data types. The Cortex-M4F code is new, so could potentially have the same problem, but there are safeguards in the code now that should prevent it. Put a break point on entry to a task (before the variable declarations), and look at the stack pointer value when the break point is hit - is it eight byte aligned?
Hmm. Which FreeRTOS version are you using, and are you using the official FreeRTOS CM4F code? If it is official code you should see something like this in the IAR CM4F port.c file:
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
{
/* Simulate the stack frame as it would be created by a context switch
interrupt. */
/* Offset added to account for the way the MCU uses the stack on entry/exit
of interrupts, and to ensure alignment. */
pxTopOfStack -= 2;
That line of code should have taken care of your problem, but may need more or less subtracting from it. I can look at this when I have some CM4F hardware with me.