1431699_en-US

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

1431699_en-US

1431699_en-US

To complement solution how to printf float number in MCUXpresso IDE

Hi:


In previous topics there are some discussions how to print float number in MCUXpresso IDE and SDK.

To try them and summarize the final solution:

1.PRINTF the float number to UART console

set below macro in project configuration->C/C++ build ->setting

PRINTF_FLOAT_ENABLE=1

such code will work.

float test1 = 0.15;

PRINTF("%f\r\n",test1);

2.Transform float number to string by sprintf() function.

there is one error in SDK user manual, " Ensure Redlib: Use floating point version of printf is selected
" during project creation does not work.

The default C library Redlib doesn't support floating, so it couldn't work with redlib.

daweiyou_0-1647929545419.png


The correct solution are:

(1)Change link library to NewLib, it's full C library and support float  printf.

But notice need include in related c file, or else sprintf(float) doesn't work as expected.

daweiyou_1-1647929662327.png

(2)Change link library to NewLib Nano, it's compact C library , and need click "enable print float" to enable float function, which actually add " -u _printf_float" link symbol.

But notice need include in related c file, or else sprintf(float) doesn't work as expected.

daweiyou_2-1647929807476.png


So the solution surely add flash & RAM consumption in project, but for i.MXRT series it's not problem.

Attach is one example for RT1020 EVK.






Re: To complement solution how to printf float number in MCUXpresso IDE

Thank you! That solved my problem. 

Re: To complement solution how to printf float number in MCUXpresso IDE

Hi @daweiyou 


Thank you so much for your contribution. The information was pretty helpful and it might be helpful for many people.


Thank you again.

Best Regards.
Pablo Avalos.

Tags (1)
No ratings
Version history
Last update:
7 hours ago
Updated by: