sprintf with float specifier - how to make it work?

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

sprintf with float specifier - how to make it work?

Jump to solution
2,507 Views
blsousan
Contributor III

I'm using KDS 3.2.0 with the MKE02Z64VLC4 processor and need to use the sprintf/snprintf functions with the float specifier %f.  However, it will not work.  It shows nothing.  I some other posts that have work-around suggestions and various things to try.  I just want to know what is the correct/recommended way of enabling sprintf/snprintf to use floating point data types for the format specifier.

Thanks,

Bill

0 Kudos
1 Solution
2,159 Views
BlackNight
NXP Employee
NXP Employee
0 Kudos
7 Replies
2,159 Views
blsousan
Contributor III

That worked - but I had to add it as (add the equal sign):

-u=_printf_float

And then select the checkbox in the linker options to adding support for float in printf.

Thanks!

0 Kudos
2,160 Views
BlackNight
NXP Employee
NXP Employee

Hi Bill,

have you added

-u _printf_float

?

See https://mcuoneclipse.com/2014/07/11/printf-and-scanf-with-gnu-arm-libraries/

I hope this helps,

Erich

0 Kudos
2,138 Views
williamcarlisle
Contributor II

This is still not working for me, and after an exhaustive search I have found no solution to get this working.

0 Kudos
2,159 Views
williamcarlisle
Contributor II

I am also having this problem, my program crashes on the first sprintf that uses a double argument.

I have checked the box "Use float with nano printf(-u _printf_float)", and it behaves the same way.

I am using MK61FN1M0VMJ12 on KDS 3.2.

This is after the program working great with no issues on Codewarrior.

So I am in the same boat as others, running out of ideas to fix this.

0 Kudos
2,159 Views
ErichStyger
Senior Contributor V

If it is crashing: can you increase the heap and stack size? printf() uses more stack and potentially heap memory (depending on the library).

0 Kudos
2,159 Views
williamcarlisle
Contributor II

Some more info - This is what shows in the console when the system crashes on the sprintf with a float.

 

BusFault: An imprecise (asynchronous) data access error has occurred.
HardFault: A fault has been escalated to a hard fault.

0 Kudos
2,159 Views
williamcarlisle
Contributor II

I am having trouble finding a define for the heap, I used this thread for assistance.

Changing Heap and Stack Size for NXP Kinetis SDK V2.0 gcc Projects | MCU on Eclipse

The linker file has nothing mentioning the heap.

Using the MQX Stack Usage view in KDS, it appears that none of my tasks are running over. This is pretty quick upon startup, so there are only a few tasks running at the point it crashes.

0 Kudos