Trying to use sprintf() with KDS

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Trying to use sprintf() with KDS

跳至解决方案
1,626 次查看
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

标签 (1)
0 项奖励
1 解答
820 次查看
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

在原帖中查看解决方案

0 项奖励
4 回复数
821 次查看
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

0 项奖励
820 次查看
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 项奖励
820 次查看
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 项奖励
820 次查看
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 项奖励