cancel
Showing results for 
Search instead for 
Did you mean: 

How to print float value with printf in TrueStudio ?

Hae Ryon Jung
Associate III
Posted on June 25, 2018 at 07:11

Hi All, 

I'd like to print float value with printf.

when I tried, printf showed blank for float value.

would you please let me know how to set TrueStudio for printing float value with printf ?

I'm using STM32F103RF.

Thanks in advance.

#float
12 REPLIES 12
Grisby
Associate II

It seem to be a general problem with sprintf https://www.mikrocontroller.net/topic/359573

May be it is a problem with _sbrk in syscall.c

My solution:

http://chibios.sourceforge.net/html/chprintf_8c_source.html

sylvain
Associate II

in TrueSTUDIO:

Project -> C / C ++ Build -> Settings -> Tool settings -> C Linker -> Miscellaneous -> Other options:

  • -u _printf_float

assuming newlib-nano as used by CubeMX.

Jordi Becares
Associate II

Hi All,

I'm working with last atollic version 9.1.0 and I used your solution (@Hae Ryon Jung​) , and it doesn't work well.

I have a program to read, every second, ADC and converts counts to voltage, the source works well (the values are good) but the text in serial com only is printed well the first time, the others the dot "." is not printed..., I give you an example:

[0]ADC 2754 2.22 V

[1]ADC 2744 221 V

[2]ADC 2745 221 V

adcVal = HAL_ADC_GetValue(&hadc1);
adcRes = adcVal*3.3/4096;
sprintf(buffTmp, "[%d]ADC %d %4.2f V\n\r", (int) counter, (int)adcVal, adcRes);

Thanks for your support

Jordi