Printing Floating point values to fsl_debug_console FRDM-K64F

cancel
Showing results for 
Search instead for 
Did you mean: 

Printing Floating point values to fsl_debug_console FRDM-K64F

Jump to solution
1,973 Views
michaellyons
NXP Employee
NXP Employee

Hello,

I'm using KDS 2.0, KDSK1.1.0, PEx, with the FRDM-K64F.  I'd like to print the Floating point accelerometer values to the terminal using fsl_debug_console.  Strings and integers print fine but it seems debug_printf() doesn't support float.  I also tried

sprintf(str,"%f");

printf("%s",str);

but everything except the floating point val would print.  Is there a compiler setting that must be changed to support floating point printing?

Thanks,

Michael

Labels (1)
1 Solution
471 Views
likeli
NXP Employee
NXP Employee

Hello Michael,

To print floating point values, you need to enable float/double support to printf() function. In KDS,  please look under: Properties->C/C++ Build->Settings->Tool Settings->Cross ARM C Linker, then add

-u _printf_float to the linker options. It will be OK.

For example, you can write code like this:

float temp=36.5;

printf("\r\n temp=%f \n\r",temp);

View solution in original post

0 Kudos
10 Replies
472 Views
likeli
NXP Employee
NXP Employee

Hello Michael,

To print floating point values, you need to enable float/double support to printf() function. In KDS,  please look under: Properties->C/C++ Build->Settings->Tool Settings->Cross ARM C Linker, then add

-u _printf_float to the linker options. It will be OK.

For example, you can write code like this:

float temp=36.5;

printf("\r\n temp=%f \n\r",temp);

View solution in original post

0 Kudos
471 Views
dave408
Senior Contributor II

I tried adding -u _printf_float to my linker settings for my application, but it didn't work:


pastedImage_0.png

Can you please tell me if I've missed something?  Thanks!

0 Kudos
471 Views
michaellyons
NXP Employee
NXP Employee

Hi Dave,

I went to Properties->C/C++ Build->Settings->Cross ARM C Compiler->Miscellaneous then in the "Other compiler flags" box I added "-u_printf_float".  That seemed to work for me.  Are you using KDS, KSDK, and PEx with the FRDM-K64F?


Thanks,

Michael

0 Kudos
471 Views
dave408
Senior Contributor II

This is so odd.  Setting the compiler flags didn't work for me, either.  I'm using KDS 2.0, KSDK 1.1, and MQX.  I am not using processor expert.  This is with a K64F.  I just found a post by Erich Styger, so I'll check that out now.  Thank you for your prompt reply!

0 Kudos
471 Views
michaellyons
NXP Employee
NXP Employee

Okay, I haven't tried this with MQX yet so that might be the difference. Screenshot below for help.

pastedImage_1.png

If you find the answer please post here.

0 Kudos
471 Views
dave408
Senior Contributor II

Ok, I'll definitely post my findings if anyone else presents a solution elsewhere.  Erich's post mentions linker settings as well, not compiler settings.  It also has a lot of detail that I'm not comfortable with, and since it mentioned PEx and not KSDK, I'm not sure it's the right direction for me.  I'll keep digging, and if I can't find the answer, I'll post up a new thread and link to it here.  Thanks!

0 Kudos
471 Views
matthias
Contributor III

Hello Dave,

I had a similar problem, so maybe this solution helps: printf() with float values

Regards,

Matthias

471 Views
dave408
Senior Contributor II

Hi Matthias, thank you *so* much for posting a link to your thread!  That was absolutely the problem, and now printf is able to display fp values.  Thanks!!!

0 Kudos
471 Views
dave408
Senior Contributor II

Ok, thanks!  That's totally not what Ke had said.  :smileyhappy:  He specifically mentioned the linker, but hey it didn't work and you got it working, so I'll try your suggestion.  Thank you!

0 Kudos
471 Views
michaellyons
NXP Employee
NXP Employee

That worked!  Thank you.

0 Kudos