In some cases, printf of floating point (%f) does not seem to work.
Solution
The IAR C/C++ Compiler for ARM requires the Stack Pointer to be aligned at 8 bytes. 8-byte alignment is required by AEABI (and some instructions generated by the compiler for some cores).
The default cstartup code automatically initializes the ARM core stack(s) to an 8-byte aligned address. Make sure that your application and/or RTOS also does this.
Background
According to the MQX release notes, stack alignment is not ensured in MQX 3.7. The behavior is corrected in MQX 3.8. This problem has also been observed with other RTOSes.
All product names are trademarks or registered trademarks of their respective owners.
评分
查看全部评分
评分
查看全部评分
评分
查看全部评分
用的是 IAR。
试了用%lf,效果一样
printf函数就是重定向到串口输出而已,打印定点数,十六进制,字符,字符串都没问题。
还有检查一下引号是否键入全角了。
评分
查看全部评分
printf("a = %4f\n",a);
的结果是 a = %f, 等号和百分号之间有三个空格。
如果符号是全角的,是不能编译通过的。
评分
查看全部评分
评分
查看全部评分
用LCD习惯了,一般先sprintf到字符串,然后再printf打印字符串。
评分
查看全部评分
先使用如下代码 sprintf 再打印字符串也是不可以的。输出结果为 %f * * * *
void printf_float(float a)
{
char tmp[8]={0};
int i;
sprintf(tmp, "%f", a);
for(i=0; i<8; i++)
printf("%c", tmp);
printf("\n");
}
问题解决了,见#13
感谢,不过应该不是这个问题吧。我没用任何OS。
问题解决了,见#13