TOOL: RVMDK V3.02a, with RealView V3.0 compiler.
I use uC/OS-II in this program. Please mail to me for a complete example. huawdg@pub.wx.jsinfo.net
Code in system_task.c:
#include <LPC22xx.H> #include "includes.h" #include "generictype.h" #include "rt_locale.h" #include "locale.h" void IRQ_Exception(void) { VICVectAddr=0; } void timer0_Exception(void) { T0IR = 0x01; OSTimeTick(); VICVectAddr=0; //interrupt routine finish } void TaskIdleHook(void) { } void DAbt_Handler(void) {} void PAbt_Handler(void) {} void Undef_Handler(void){} void FIQ_Handler(void) {} extern void IRQ_Handler(void); extern void timer0_Handler(void); #define SIZE_TASKSTART_STK 800 static OS_STK TaskStartStk[SIZE_TASKSTART_STK]; //timer0: 10ms void timer0_Init(void) { T0IR = 0xffffffff; T0TC = 0; T0TCR = 0x01; T0PR = 0; T0MCR = 0x03; T0MR0 = 110592; } void VICInit(void) { VICIntEnClr = 0xffffffff; VICDefVectAddr = (unsigned long)IRQ_Handler; VICVectAddr1 = (unsigned long)timer0_Handler; VICVectCntl1 = (0x20 | VICINT_NUM_TIMER0); VICIntEnable = 1 << VICINT_NUM_TIMER0; } void task_Start(void *pdata) { char s[100]; VICInit(); timer0_Init(); sprintf(s,"float=%f",12.345); //wrong result sprintf(s,"float=%f",8871.5678); //wrong result while(1); } int main(void) { setlocale(LC_ALL,"C"); VICIntEnClr = 0xffffffff; OSInit(); OSTaskCreate(task_Start, (void *)0, &TaskStartStk[SIZE_TASKSTART_STK - 1], 5); OSStart(); return 0; } void _sys_exit(int return_code) { label: goto label; /* endless loop */ }
"wrong value" is a bit vague.
What value were you expecting?
What value did you observe?
How (i.e., by what means) did you observe it?
As Dan says, "wrong result" is very uninformative!
"I use uC/OS-II in this program."
Go back to basics - create a simple "Hello, World", standalone application (no operating system, etc), and try your floating-point printf there: If it works, there's probably something wrong with your uC/OS-II setup; If it doesn't work, there's probably something fundamentally wrong with your basic floating-point support setup/configuration.
"Please mail to me for a complete example."
It's up to you to present the smallest, complete example that illustrates the problem.
Do you have your stack 8-byte aligned? Floating point in RealView compiler requires 8-byte aligned stack. If this is not the case you might get the results you are seeing.
Franc
This is a smallest,complete example. bbs.21ic.com/.../200682885943927.zip
If call task_Start() in main() function, the result will be right. If move "system" group to first place, the result will also be right.
Please try this example. bbs.21ic.com/.../200682885943927.zip
The stack is 8-byte aligned. This is an example. bbs.21ic.com/.../200682885943927.zip
You still haven't answered Dan's original questions...
Franc is right. Thanks. When use __align(8) modifier for TaskStartStk, the problem is solved.