To complement solution how to printf float number in MCUXpresso IDE

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

To complement solution how to printf float number in MCUXpresso IDE

1,815 Views
daweiyou
NXP Employee
NXP Employee

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 <stdio.h> 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 <stdio.h> 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.

 

 

 

 

 

0 Kudos
1 Reply

1,786 Views
PabloAvalos
NXP TechSupport
NXP TechSupport

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.

0 Kudos