cancel
Showing results for 
Search instead for 
Did you mean: 

CubeIDE sprintf does not work with %f

KWuer
Associate II

When I create a new project and put in "-u _printf_float"  as linker option and select "Use float with printf from newlib-nano (-u _printf_float) then sprintf does not convert float values.

but when I import a TrueStudio project where sprintf works with floats, then it works also in CubeIDE. What did I miss?

Compiler Settings:

-mcpu=cortex-m4 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32F446xx -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Include -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb

Linker settings:

-mcpu=cortex-m4 -T"D:\HiDrive\STM32\workspace_1.0.0\printf\STM32F446RETX_FLASH.ld" --specs=nosys.specs -Wl,-Map="${ProjName}.map" -Wl,--gc-sections -static -u _printf_float --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -Wl,--start-group -lc -lm -Wl,--end-group

11 REPLIES 11

Well, thank you for the explanation's link. This is very interesting to learn, and lead me to review the memory management options set within CubeIDE project. This had more impacts than I expected but works well if you correctly follow the implementation suggested by DRNadler. Nevertheless this doesn't explain why simply removing the faulty _sbrk function works (but maybe doesn't works well, in fact I can't find the function that could be called instead...).

Bless your souls for mentioning _sbrk this was driving me up the wall