cancel
Showing results for 
Search instead for 
Did you mean: 

sprintf weirdness...

grheard
Associate II
Posted on May 06, 2009 at 14:24

sprintf weirdness...

3 REPLIES 3
grheard
Associate II
Posted on May 17, 2011 at 13:11

Quote:

On 09-04-2009 at 15:52, Anonymous wrote:

Hi all,

I am in big trouble with my app, EWARM 5.20 + uC/OS II. I have a task writing a floating on an output buffer, like this:

char outval[16];

float me->INval__ = 123.456;

sprintf (outval, ''%f'', me->INval__);

well, sprintf writes randomly ''0.000'' or ''-nan'' (or other garbage) to outval buffer.

I stepped thru all the (s)printf assembler to check the stack pointer, it stays inside his bounds. I tried changing from ARM mode to THUMB mode, no relief. The strangest thing of all, if I put a simple sprintf loop in main task without creating any other task sprintf woks well. Something to do with task switching ?

I saw this over in the arm 9 forum and it is exactly what I started to experiencee. Mine is with IAR v5.30 uC/OS-II v2.88 on an STM32F103 Cortex-M3 microcontroller. sprintf works fine if used in main before invoking OSStart(). Upon entering the ''start task'', sprintf no longer works. Understand that there is no task switching going on as the system only has this 1 high priority task. Also, IAR's documentation declares that the sprintf varieties are reentrant safe. I'm very perplexed, this was working fine a day or two ago with all 10 system tasks running. The oddity is that only the float conversions are affected. All other number conversions continue to operate normally.

cgrun
Associate II
Posted on May 17, 2011 at 13:11

Hi,

using an other RTOS, i've encounter the same problem with printf and double.

The problem was that the OS doesn't align by 8 the stack of my task, and the arm library need to have all double, and long long object to be really aligned by eight, it's mandatory...

For you it works sometimes since there is 50% of chance that the linker put the stack at a 8 byte boundary...

try to align all stack for your tasks, and see if it works.

sincerely

cgrun

grheard
Associate II
Posted on May 17, 2011 at 13:11

You are correct sir.

The task stacks were only 4 byte aligned by default. After aligning them to 8 bytes, the sprintf float issue was corrected.

Thank you for taking the time to reply.