STM32F407 sprintf with float value

Discussions concerning TrueSTUDIO for STM32 9.0.0 and later versions.

Moderators: Markus Girdland, Mattias Norlander

MRomano
Posts: 4
Joined: Mon Mar 12, 2018 6:56 am

STM32F407 sprintf with float value

Postby MRomano » Thu Mar 14, 2019 10:03 am

Hi everyone,
I use Atollic TrueSTUDIO® for STM32, Version: 9.3.0 with option USE_HAL_DRIVER

I want to use a sprintf with float value as follow:

char sTemp[50];
float t1 = 25.5;
sprintf(sTemp, "%f;", t1);

but the string always contains the value "0.00000"

I tried both with the Newlib-Nano nano and Newlib standard libraries, adding the "-u _printf_float" flag to the linker and "-mfloat-abi=soft" to the compiler. I also followed other solutions proposed in the forum, but unfortunately I can't get a consistent result.

I tried to compile the code with the USE_STDPERIPH_DRIVER option and the sprintf of a float value works correctly.
I believe the problem appears when using the USE_HAL_DRIVER option.

Please someone can suggest me a solution. I am very worried because I can't solve this problem.

Thanks MRomano

HowardHo
Posts: 3
Joined: Wed May 22, 2019 12:34 am

Re: STM32F407 sprintf with float value

Postby HowardHo » Fri May 31, 2019 7:29 pm

Did you get an answer for the question. When I try:
char ab[100] = "this is fubar";
float j = 104.3;
sprintf(a, "%f,%s\r", j, ab);

The value of j never get resolved, i.e. doesn't print out and a is ",this is fubar".

How do I fix this?

kurta999
Posts: 21
Joined: Thu Sep 06, 2018 8:27 am
Location: Slovakia
Contact:

Re: STM32F407 sprintf with float value

Postby kurta999 » Sat Jun 01, 2019 9:25 am

https://github.com/mpaland/printf

I would recommend using this one, the newlib printf is piece of s..t. It just eats ~10KB more when you enable support for floating point.

HowardHo
Posts: 3
Joined: Wed May 22, 2019 12:34 am

Re: STM32F407 sprintf with float value

Postby HowardHo » Sun Jun 09, 2019 6:24 pm

kurta999,
That worked fine. Thank you.


Return to “TrueSTUDIO for STM32 discussions”

Who is online

Users browsing this forum: No registered users and 1 guest