snprintf() does not appear to work with floating point format within a task. Appears to work normally from main().
Please advise why, and what other functions may be affected similary?
I modified a 'blinky' project and observed the fault under simulation, single step, watch memory 'buffer'.
Seems to work ok if called from main.
---------------------------------------------- char buffer[100];
void test1(void) { float f;
f = 3.14159;
snprintf(buffer,100-1,"%f",f);
/* HELP!!!!! contents of buffer are now '0.000000' , should be '3.141590' */ } /*---------------------------------------------------------------------------- * Task 1 'phaseA': Phase A output *---------------------------------------------------------------------------*/ void phaseA (void) __task { for (;;) { test1(); os_evt_wait_and (0x0001, 0xffff); /* wait for an event flag 0x0001 */ IOSET = LED_A; signal_func (t_phaseB); /* call common signal function */ IOCLR = LED_A;
} } -------------------------------------------------------------------
Oops, tvo errors in the previous post...
Error one was that I intended to mention s(n)printf and not *printf.
Error two was that I missed that s(n)printf is in the list of thread-safe functions.
The problem might be much simpler. Can you check if the stack is 8-byte aligned?
The newer versions of the RTX configuration file ensure that, but in early versions (before MDK 3.00) there was a way to mis-align the stack.
see: http://www.keil.com/support/docs/3387.htm
Thanks very much everyone, I'm now back to 3.141590. -Pete.