2019-05-07 04:33 PM
Float in printf doesn't seem to work in new projects created in stm32cubeide
If i create a project in sw4stm32 it works, there, it also works if i import the sw4stm32 project, it does not work if i create a new project in cubeide
In all cases the option -u _printf_float is used, but in case of new cubeide project, this setting is somehow ignored and the wrong prinf is included, visible in mapfile
good (imported project):
../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libc_nano.a(lib_a-nano-vfprintf_float.o)
bad(new project):
../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libc_nano.a(lib_a-printf.o)
Solved! Go to Solution.
2019-05-08 03:18 AM
Besides enabling -u _printf_float (either by manually typing in MCU GCC Linker/Miscellaneous or checking option in MCU Settings), please modify _estack in linker script for example from 0x2001ffff to 0x20020000 as described in the thread:
https://community.st.com/s/question/0D50X0000AldaPzSQI/cubeide-sprintf-does-not-work-with-f
2019-05-07 10:23 PM
> bad(new project):
> ../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libc_nano.a(lib_a-printf.o)
This most probably means you selected a library version without float support in this case.
I'm no CubeIDE user, but such options are usually set while creating the project. Check the IDE documentation/help on how to fix it.
2019-05-07 11:25 PM
2019-05-08 01:45 AM
Thanks,
There is not need to repeat what i said, i know that this is the problem, the wrong printf is included even tho I specified that I want the float one with the linker flag -u _printf_float. The -u _printf_float is what is supposed to fix this, and it does for the imported project, but not for the newly generated one
2019-05-08 02:22 AM
> There is not need to repeat what i said, ...
It is. as reference to the point I'm referring to.
> The -u _printf_float is what is supposed to fix this, and it does for the imported project, but not for the newly generated one
Perhaps because it referenced another library ? You could compare the sw4stm32 version and the CubeIDE version, to find out.
Check the CubeIDE documentation, as said.
2019-05-08 02:49 AM
This is so annoying I spent so much time on this.
Now i checked that the right printf is included but it only prints 0.0
The testcode is very simple, just create a standard template project for any stm32 (i tested this stm32f746ng), add code below somewhere
add option "Use float with printf from newlib-nano (-u _printf_float)" in the Tool Settings\MCU Settings
check the buffer via debugger.
any ideas on this?
volatile float a = 3.14f;
char buff[100];
while(1){
sprintf(buff, "a= %f", a);
a+= 0.001234;
}
stm32ide project -> it only prints a=0.0
sw4stm32 project-> works correctly
2019-05-08 02:56 AM
what exactly do you mean by the cubeide documentation?
You have any specific one in mind? otherwise this is just trolling, It doesn't work, oh you should check 'the documentation'
I checked many documentations..
2019-05-08 02:59 AM
Did you try the Runtime Library "Standard C" and the option Use float with printf from newlib-nano (-u _printf_float) together?
Because this Setting works at my projekt.
2019-05-08 03:10 AM
Thanks for the feedback,
I tried newlib (nano.spec) and standard lib, i have the same wrong result in both cases.
But -u _printf_float makes sense only if newlib-nano is used, is it not?
The difference is that the sw4stm32 is a c only project the stm32cubeide is a c++ one (tho only c code is used).
the first one is linked with arm-none-eabi-gcc, the other with arm-none-eabi-g++
I think the problem is in this area somehow, both have the same options, the c++ one has additional options (-lstdc++ -lsupc++)
Edit:
Note: the stm32 project wizard always creates a c++ project, even if i select c project
2019-05-08 03:18 AM
Besides enabling -u _printf_float (either by manually typing in MCU GCC Linker/Miscellaneous or checking option in MCU Settings), please modify _estack in linker script for example from 0x2001ffff to 0x20020000 as described in the thread:
https://community.st.com/s/question/0D50X0000AldaPzSQI/cubeide-sprintf-does-not-work-with-f