Skip to main content
MFend
Associate III
June 27, 2019
Solved

u_printf_float - where to set for C_Linker in STM32CubeIDE?

  • June 27, 2019
  • 11 replies
  • 19531 views

When I compile, I get the following error:

The float formatting support (-u_printf_float)is not enabled from linker flags

I can't find Linker flags/Options/Settings for C - just for MCU G++ Linker. When I chose the option, it still didn't remove the error. It compiles, though and can be run.

0690X000009Xcm0QAC.jpg

This topic has been closed for replies.
Best answer by Yuk117

This problem is fixed in STM32CubeIDE ver.1.0.2.

Workaround in older version is to add "-u _printf_float" to MCU GCC Linker -> Miscellaneous -> Other flags.

0690X000009Yu2qQAC.png

11 replies

MFend
MFendAuthor
Associate III
July 8, 2019

Where is LDFLAGS (linker flags) set?

MFend
MFendAuthor
Associate III
July 17, 2019

I've been asked to introduce this new IDE to the other FW developers on our team.

I still have this float-printf problem .

0690X000009YoojQAC.jpg

Even after I choose the settings, I get the error...

MFend
MFendAuthor
Associate III
July 17, 2019

The linker command shown in the console window:

arm-none-eabi-g++ -o 4040D_STM32Cube.elf Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal.o

...

...

Src\values_log.o startup_stm32l451xx.o -mcpu=cortex-m4 -TF:\work\FlameDetectors\4040D_STM32Cube\stm32l4_flash.ld --specs=nosys.specs -Wl,-Map=4040D_STM32Cube.map -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -u _scanf_float -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group 

In the linker command I see that -u_printf_float is defined - and still I get the errors that printf doesn't support float!!!

Gpeti
Senior
July 17, 2019

You are using "newlib-nano" standard C library and it doesn't support float printf anyway. So even if you fix your compilation / link option issue, it will not work (for example a printf of a float will return 0.0000).

if I remember correctly (not sure though), "newlib" should support float printf.

MFend
MFendAuthor
Associate III
July 17, 2019

Thanks for noticing that...

I changed the library to the regular C/C++ standard, and I still get the error. (I Rebuilt the whole project)

Gpeti
Senior
July 17, 2019

" It compiles, though and can be run" So it is a build error or not ? It's not clear. And can you printf float variables at the end ?

MFend
MFendAuthor
Associate III
July 17, 2019

As you've seen yourself - these errors are mentioned, but the project can be debugged.

I haven't been able to see the printfs in the SWV console - that's another thread that I opened in the forum...

0690X000009YpHNQA0.jpg

Gpeti
Senior
July 17, 2019

There is the known bug about stack, see for example this thread:

https://community.st.com/s/question/0D50X0000AldaPzSQI/cubeide-sprintf-does-not-work-with-f

MFend
MFendAuthor
Associate III
July 17, 2019

but the _estack pointer is fine in the .ld file...

I saw all of the threads - but they don't seem relevant

/* Highest address of the user mode stack */

_estack = 0x20020000;  /* end of 128K RAM */

Gpeti
Senior
July 17, 2019

Just to clarify:

1) I made a mistake, it seems like newlib-nano does support float printf

2) the problem comes from the stack initialisation bug

This issue is discussed many times on different forums on the web but it's a bit confusing.

kurta999
Senior
July 17, 2019

I suggest to using this library instead of this linker option.

https://github.com/mpaland/printf

Try to use built-in pritf with RTOS, SWO tracing & floating point support. Good luck :D.

MFend
MFendAuthor
Associate III
July 17, 2019

Are there any other directions for using this library? What settings do i need to set in the IDE?

Gpeti
Senior
July 17, 2019

If you are trying to print on SWV console I cannot help you since I was never able to make it work (on TrueStudio on STM32L4 few months ago I gave up, on STM32CubeIDE and STM32H7 there is a different issue for which I started a dedicated thread).

If you are trying to print in a UART console (via virtual com port or physical RS232), I think the only setup at IDE level is this "float printf" option, and apart from that implement __io_putchar or _write fucntion and configure UART, you can easily find how to do on the web.

Yuk117
Yuk117Best answer
Associate II
July 19, 2019

This problem is fixed in STM32CubeIDE ver.1.0.2.

Workaround in older version is to add "-u _printf_float" to MCU GCC Linker -> Miscellaneous -> Other flags.

0690X000009Yu2qQAC.png