Skip to main content
DZimm.9
Associate III
May 27, 2019 3:04 PM UTC
Solved

CubeIDE sprintf %f is not working

Hi there,

I imported a Attolic studio project to the STM32CubeIDEand everything works execpt printf...

I'm trying to get the sprintf running in the new STM32CubeIDE and there are already several fixes available:

Unfortunately, none of these fixes work for me... In my linker file there is the following line: _estack = 0x20020000;  /* end of 128K RAM */, which should be fine.

My linker settings:

gcc -mcpu=cortex-m4 -T"../stm32f4_flash.ld" --specs=nosys.specs -Wl,-Map="${ProjName}.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 -Wl,--end-group

As you can see, -u printf_float is added and in the map file ../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libc_nano.a(lib_a-nano-vfprintf_float.o gets included.

Scanf however is working and I can read a float from a string...

sscanf(tmpConstChar,"%f",&tmpFloat);
sprintf(print_string,"New temperature setpoint: %2.2f\n", tmpFloat);

Prints:

New temperature setpoint: .2f

I really appriciate any input on this topic...

Thank you very much and best regards

Daniel

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
May 27, 2019 3:32 PM UTC

Perhaps look at a disassembly to see why it is using the wrong code.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
May 27, 2019 3:32 PM UTC

Perhaps look at a disassembly to see why it is using the wrong code.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
DZimm.9
DZimm.9Author
Associate III
May 27, 2019 3:49 PM UTC

Well thanks for this input. There is a file from Atollic studio called tiny_printf.c which overwritte the functions even though they were linked correctly... Removing the file and using the libs directly solved the issue.

Thanks and best regards

Daniel