Trying to use sprintf() with KDS

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to use sprintf() with KDS

Jump to solution
1,018 Views
chrissorrentino
Contributor I

hi,

i just installed KDS v1.1 and trying to use sprintf() with floating point numbers on the Freedom KL25z board. I added the -u _printf_float to the linker flags but when i try to debug my program stops. I am a newb to this stuff and have been reading as much as i can to try to fix it but am at a loss.

 

here is a screenshot from the debugger

 

thanks

Labels (1)
0 Kudos
1 Solution
212 Views
BlackNight
NXP Employee
NXP Employee

Hi Chris,

the problem is that sprintf() requires a heap for the newlib-nano implementation of that particular version of newlib-nano included in KDS.

This is already mentioned in the release notes (not particularly in the context of sprintf(), but obviously this applies for this case too).

I see that you are using a Processor Expert project, so increase the heap size to at least 0x400 (see below, and see Switching between ‘tabs’ and ‘no-tabs’ UI in Processor Expert | MCU on Eclipse if you want the same view).

pastedImage_0.png

As a reference, I have attached my test project, where I was able to reproduce your problem with a heap size of zero, and then it worked when I increased the heap for the newlib-nano.

I hope this clarifies the problem, and with this you can solve it.

Erich

View solution in original post

0 Kudos
4 Replies
213 Views
BlackNight
NXP Employee
NXP Employee

Hi Chris,

the problem is that sprintf() requires a heap for the newlib-nano implementation of that particular version of newlib-nano included in KDS.

This is already mentioned in the release notes (not particularly in the context of sprintf(), but obviously this applies for this case too).

I see that you are using a Processor Expert project, so increase the heap size to at least 0x400 (see below, and see Switching between ‘tabs’ and ‘no-tabs’ UI in Processor Expert | MCU on Eclipse if you want the same view).

pastedImage_0.png

As a reference, I have attached my test project, where I was able to reproduce your problem with a heap size of zero, and then it worked when I increased the heap for the newlib-nano.

I hope this clarifies the problem, and with this you can solve it.

Erich

View solution in original post

0 Kudos
212 Views
chrissorrentino
Contributor I

Thanks, i did read about changing the heap setting and i thought i did so. i went back and did it again and it works.

0 Kudos
212 Views
ciful
Contributor II

Good morning Chris & Erich.

And if you don't use PE ? How it's possible to fix it ?

With an integer number sprintf works perfectly. With float or double it returns "" and no coversion is done.

Thanks a lot.

Claudio

0 Kudos
212 Views
BlackNight
NXP Employee
NXP Employee

Hi Claudio,

see printf() and scanf() with GNU ARM Libraries | MCU...

You need to add

-u _printf_float

to the linker options to enable float/double support to printf/sprintf()

Erich

0 Kudos