We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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;
} } -------------------------------------------------------------------
Note that no *printf() functions are listed on this page: http://www.keil.com/support/man/docs/armlib/armlib_chdfgjej.htm
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.