cancel
Showing results for 
Search instead for 
Did you mean: 

CubeIDE sprintf %f is not working

DZimm.9
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

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

View solution in original post

2 REPLIES 2

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
DZimm.9
Associate II

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