Printf won't print floats

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Printf won't print floats

ソリューションへジャンプ
5,524件の閲覧回数
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,439件の閲覧回数
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,439件の閲覧回数
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,440件の閲覧回数
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.