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
1 ACCEPTED SOLUTION

Accepted Solutions
Hae Ryon Jung
Associate III
Posted on June 25, 2018 at 09:51

Thanks to you all,

I could print float value by adding '-u _printf_float' as you said.

following captureis project property , add it like this at Settings -> C- Linker -> Command: arm-atolic-eabi-gcc -u _printf_float

0690X0000060PH8QAM.jpg

View solution in original post

12 REPLIES 12
AvaTar
Lead
Posted on June 25, 2018 at 07:34

I don't know TrueStudio in detail, but I suspect their printf implementation does not support float/double arguments and formatting.

This is quite common, to keep code sizes small. You can check the documentation, or the source code, if available.

Tobias Wedell
Associate II
Posted on June 25, 2018 at 08:06

Have you tried to add 

-u _printf_float to your linker flags?

Hae Ryon Jung
Associate III
Posted on June 25, 2018 at 08:23

my linker option is as follows.

-mthumb -mcpu=cortex-m3 -T'../STM32F103RF_FLASH.ld' -specs=nosys.specs -static '-Wl,-Map=${BuildArtifactFileBaseName}.map' -Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x80 -Wl,--start-group -lc -lm -Wl,--end-group -specs=nano.specs

would you let me know how to add -u __printf_float to linker option ?

Hae Ryon Jung
Associate III
Posted on June 25, 2018 at 09:51

Thanks to you all,

I could print float value by adding '-u _printf_float' as you said.

following captureis project property , add it like this at Settings -> C- Linker -> Command: arm-atolic-eabi-gcc -u _printf_float

0690X0000060PH8QAM.jpg

Posted on June 25, 2018 at 08:39

Sorry can't help you. I'm using Eclipse. 

Posted on June 25, 2018 at 08:46

my linker option is as follows.

-mthumb -mcpu=cortex-m3 -T'../STM32F103RF_FLASH.ld' -specs=nosys.specs -static '-Wl,-Map=${BuildArtifactFileBaseName}.map' -Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x80 -Wl,--start-group -lc -lm -Wl,--end-group -

specs=nano.specs

The nano-lib version has definitely no printf float support.

Posted on June 25, 2018 at 09:34

please let me know how to change it, in TrueStudio

Grisby
Associate II

I want use sprintf for float with STM32H7. If I use Newlib-nano unter C/C++ Build -> Settings-> ToolSetting -> General it works with integer and without float. With Newlib standard I get an error in startup-script at Line 10.

"Failure at line: 10 in 'Target Software startup Skript'. Please edit the debug configuration settings.

Error writing data to flash"

With "-u __printf_float" in C-Linker->Miscellaneous->Other options with Newlib-nano I get the same error.

# Set flash parallelism mode to 32, 16, or 8 bit when using STM32 F2/F4 microcontrollers
# 2=32 bit, 1=16 bit and 0=8 bit parallelism mode
# monitor flash set_parallelism_mode 2
 
# Set character encoding
set host-charset CP1252
set target-charset CP1252
 
# Load the program executable
 load		
 
# Enable Debug connection in low power modes (DBGMCU->CR)
set *0xE0042004 = (*0xE0042004) | 0x7
 
# Set a breakpoint at main().
tbreak main
 
# Reset to known state
monitor reset
 
# Run to the breakpoint.
continue

AVI-crak
Senior

If there are forces to step away from the general path.

https://bitbucket.org/AVI-crak/sprint/src/default/