Loading...
 
Skip to main content

System Workbench for STM32


sprinf conversion of float is not working for STM32F7

I'm tryint to use sprintf to convert a float to a string, but the returned string is empty (just the '\0' is returned).
Do any of you know of a trick that can make it work?

I'm using the latest versions of AC6 and the "Hello World" example from cube.

/Breinholm

Tunisia

Hello Breinholm,

Check your linker flags (project properties > C/C++ Build > Setings > Tool Settings (TAB) > MCU GCC Linker > Miscellaneous > Linker flags),
if you are using nanolib "-specs=nano.specs" you need to add "-u _printf_float" to enable float printf.

Best Regards,
TarekB

Hi Tarek,

I treid adding "-u _printf_float" to enable float printf. as you suggest but after build i get the following errors?


Building target: EM34.elf
Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -specs=nosys.specs -specs=nano.specs -Xlinker -u _printf_float -T"../STM32F103CBTx_FLASH.ld" -Wl,-Map=output.map -Wl,--gc-sections -lm -o "EM34.elf" @"objects.list"
arm-none-eabi-gcc.exe: error: _printf_float: No such file or directory
make: *** EM34.elf Error 1

I am using latest updates for STM32 CubeMX, and STM32 Workbench..... I recall this solution used to work on previuos version but not now?
Any suggestions?

Hi,

I think you put the "-u _printf_float" on the wrong place, it should be in the linker flags and not the -Xlinker area.

Regards
Kevin.

Hi Tang,

I am sure I put the options under the Linker Flags, as I said this option was working under previous versions (unsure which version it was) but I recently clicked "update" on both the STM32 CubeMX and the System32 Workbench programs and now for some unlknown reason The Linker throws the following errors:

Building target: EM34.elf
Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -specs=nosys.specs -specs=nano.specs -Xlinker -u _sprintf_float -Xlinker -u _printf_float -T"../STM32F103CBTx_FLASH.ld" -Wl,-Map=output.map -Wl,--gc-sections -lm -o "EM34.elf" @"objects.list"
arm-none-eabi-gcc.exe: error: _sprintf_float: No such file or directory
arm-none-eabi-gcc.exe: error: _printf_float: No such file or directory
make: *** EM34.elf Error 1

(see attached image)


Tunisia

Kevin is right :
"-u _printf_float" should be after "-specs=nano.specs"

Notes :
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -specs=nosys.specs -specs=nano.specs -Xlinker -u _sprintf_float -Xlinker -u _printf_float -T"../STM32F103CBTx_FLASH.ld" ....

  1. There is no "_sprintf_float"
  2. You do not need Xlinker options
  3. You should have only one -u _printf_float
  4. In (project properties > C/C++ Build > Setings > Tool Settings (TAB) > MCU GCC Linker > Miscellaneous > Linker flags),you should have " -specs=nosys.specs -specs=nano.specs -u _printf_float"

Many thanks tarek,

My problem issue was that was adding the "-u_printf_float" option using the "ADD ICON" which put the required string into the TEXT BOX below ? ..
This was working ok on previous versions of Sytem32 Workbench ...but ... The Latest version doesn't work like that anymore ... so what I did was to edit/replace the main string at the top ( -specs=nosys.specs -specs=nano.specs ) to what you have shown above .(-specs=nosys.specs -specs=nano.specs -u _printf_float). this worked OK ..
Thanks again for your help.😀