Printf won't print floats

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Printf won't print floats

跳至解决方案
5,531 次查看
GaryOlmstead
Senior Contributor I

I am using the K60 with MCUxpresso. The printf command works, but won't print floats.  I've had this before, so I know to delete the CR_PRINTF_INTEGER from the preprocessor list.  I've done that, and also PRINTF_FLOAT_ENABLE is set to 1.  The Quick start menu Quick Settings >> Set floating point type list is all grayed out. 

Not unrelated, I am also getting compiler errors that the code is using floating point commands for a unit that doesn't have floating point.

Any ideas?

pastedImage_1.png

1 解答
5,446 次查看
GaryOlmstead
Senior Contributor I

Although I would have bet money that I had selected the floating point printf option when I created the project, I created a new project, making doubly sure to select floating point printf, then copied and pasted all the old code into the new project.  The compiler errors disappeared, and the program runs and prints floats just fine.

For anyone else reading this to fix a similar problem, I should have mentioned that I am using redlib.  I've come to the conclusion that there is some piece of MCUxpresso that controls the use of floats, that is not changed by messing with the pre-processor list.  Whatever it is is only set by ticking the box for floating point printf at project creation time.  I haven't used neolib, it may be completely different.

Thanks for your help, Erich.  I'd say stay safe, but judging by Switzerland's Covid-19 stats, that won't be a problem.

在原帖中查看解决方案

2 回复数
5,446 次查看
ErichStyger
Specialist I

Hello,

it depends on the library you are using. See printf() and scanf() with GNU ARM Libraries | MCU on Eclipse , for the GNU nano lib you have to turn things on in the linker:

pastedImage_2.png

I hope this helps,

Erich

0 项奖励
回复
5,447 次查看
GaryOlmstead
Senior Contributor I

Although I would have bet money that I had selected the floating point printf option when I created the project, I created a new project, making doubly sure to select floating point printf, then copied and pasted all the old code into the new project.  The compiler errors disappeared, and the program runs and prints floats just fine.

For anyone else reading this to fix a similar problem, I should have mentioned that I am using redlib.  I've come to the conclusion that there is some piece of MCUxpresso that controls the use of floats, that is not changed by messing with the pre-processor list.  Whatever it is is only set by ticking the box for floating point printf at project creation time.  I haven't used neolib, it may be completely different.

Thanks for your help, Erich.  I'd say stay safe, but judging by Switzerland's Covid-19 stats, that won't be a problem.