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
Solved! Go to Solution.
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);
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);
I tried adding -u _printf_float to my linker settings for my application, but it didn't work:
Can you please tell me if I've missed something? Thanks!
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
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!
Okay, I haven't tried this with MQX yet so that might be the difference. Screenshot below for help.
If you find the answer please post here.
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!
Hello Dave,
I had a similar problem, so maybe this solution helps: printf() with float values
Regards,
Matthias
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!!!
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!
That worked! Thank you.