Keil - floating point support

kheksel wrote on Monday, March 16, 2009:

I have problem with floating point formatting of sprintf function. Integer formatting works fine. Is there something rtos specific, I should setup?
Thanks for any clue.

edwards3 wrote on Monday, March 16, 2009:

Are you saying it only doesn’t work when you are using the RTOS? So in a small non RTOS APP the floating point formatting does work?

kheksel wrote on Tuesday, March 17, 2009:

It looks like…
The following line of code works with non-rtos version of application.

sprintf(CommonBuffer,"I =%5.2fA   Delta =%4.1f%%\n", (float)current/100,  (float)CalcDeviation(current)/10);

In rtos version of appplication formatting itself look ok, but values of formatted variables are not right (usually zeros).

Keil 3.40, FreeRTOS 5.1.2, LPC2388


icefishhead wrote on Tuesday, March 17, 2009:

May be it is because the sprintf() function is reenterable. I just guess.


djg wrote on Wednesday, March 18, 2009:

I had a similar problem with floating point on the FreeRTOS Luminary Stellaris demo.
The problem is the float is passed in as a 64 bit double and the ARM requires it to be aligned to 64 bits. The demo set the stack up 32 bit aligned. The changes I made to 4.7.2? using GCC were

added the attribute to stack declaration to force 64 bit alignment
static unsigned long __attribute__ ((aligned (8))) pulStack[STACK_SIZE];

changed to
#define portBYTE_ALIGNMENT                    8

(I also had to add floating point printing to the supplied printf)

kheksel wrote on Wednesday, March 18, 2009:

This is the point. The problem is with passing 64 bit variable as function parameter in Task.
When, during debugging, I changed appropriately SP the sprintf function started working correctly.

I tried to setup my Keil project similarly, but unfortunately without success.
I appreciate any hints.

kheksel wrote on Wednesday, March 18, 2009:

I managed it running under heap_2 memory model.
The modifications should be exactly like "dig" suggested.
For Keil it is:

#define portBYTE_ALIGNMENT      8
in portmacro.h

__align(8) static struct xRTOS_HEAP
    unsigned portLONG ulDummy;
    unsigned portCHAR ucHeap[ configTOTAL_HEAP_SIZE ];
} xHeap;
in heap_2.c

I am still confused in heap_3 memory model for which the problem still exists.
I checked. Configuration of heap in Startup.s file is 8 bytes aligned.
So why it does not work in this case?