MK22F printf floating point numbers in KDS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MK22F printf floating point numbers in KDS

1,191 Views
mci
Contributor III

Hello,

We have a 2-year old custom board that was developed with Kinetis K22FX512 MCU.

I'm doing code re-engineering and maintenance of its firmware inside Kinetis Design Studio IDE for 1.5 years to add new features as requested for the product's enhancements and upgrades.

All these years, all the numeric data are integers.

Now, I am required to change of the16-bit integer data to floating point, e.g. instead of 999 seconds, I'm converting to 99.9 minutes.  This way, timer can go above 16+ minutes in 16-bit as well as for limit 3-character display that can only show 3 digit positions.

Before altering anything about this data, I had to first try defining, declaring and printing a floating point variable.

I searched previous posts on this forum about "PRINTF_FLOAT_ENABLE" and such.   I found about 3 threads from 2015 about the matter and tried them all out, changing "settings" in project's property in compiler and linker sections.  However, none of them works.   I get the same result as those posts reported, whereby only "f" is printed in place of the %f in the printf() function.  I even #included <float.h> standard C library but still the same problem.  Only character "f" prints on the debug console.

Does anyone else know how to fix this problem for this MCU in KDS?

Thanks for your help.

MI

Labels (1)
0 Kudos
4 Replies

1,009 Views
mci
Contributor III

Hi Erich and Jing,

Thanks for your instructions.

I apologize if I was not clear, but I am using a USB - FTDI UART protocol connected terminal emulator console outside of KDS (and MCUXpresso on the other project).   I'm not using the "Console" tab inside KDS.    I see message dumps there for builds, erase, programming and debug start but I dump all printf's out through UART.

I found one of old posts that is what I tried yesterday & it works by basically separating the whole number part from the decimal place part of the floating point number, and then concatenating them together as a "string" by sprint.

I think that's what I'll be implementing here onwards.   Afterall, this display is only for debugging purposes.   I know internally in the float variable, the format is a float and all math computations work normal on the float.

You may refer to this link where I found this method: 

https://community.nxp.com/thread/438758

Let me know if you have any further comments or suggestions.

Thanks again for the help,

MI

0 Kudos

1,009 Views
ErichStyger
Senior Contributor V

What library are you using?

E.g. for newllib nano there is a dedicated option for this:

pastedImage_1.png

Erich

0 Kudos

1,009 Views
jingpan
NXP TechSupport
NXP TechSupport
0 Kudos

1,009 Views
ErichStyger
Senior Contributor V

Hi Mi,

see Semihosting with GNU ARM Embedded (Launchpad) and Kinetis Design Studio | MCU on Eclipse 

Section

Printf() and Scanf() with Floating Point

I hope this helps,

Erich

0 Kudos