2019-04-29 11:34 AM
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
2019-04-29 02:10 PM
It looks like that I found the problem. The linkersript is wrong. The value _estack = 0x2001ffff; should be point one byte after the stack _estack = 0x20020000;
Then snprintf works again.
See also: https://stackoverflow.com/questions/28746062/snprintf-prints-garbage-floats-with-newlib-nano
2019-04-29 03:52 PM
>>The value _estack = 0x2001ffff;
I can't believe that continues to permeate
2019-07-08 02:15 PM
Just wasted several hours until I found that stackoverflow answer... yay!
2020-02-18 11:55 PM
I'm experiencing the same problems using
STm32cubeide Version: 1.2.1 with Nucleo-F446RE.
My printf works with strings and integers but crashes
my microcontrollor when i try to print floats.
You have said that the mistake is in linker file definition
_estack.
In my link file i read:
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
What do you think?
G.
2020-02-19 02:34 AM
Your _estack is OK. Look for soft/hard floating point compiler configuration and this:
https://community.st.com/s/question/0D50X0000BB1eL7SQJ/bug-cubemx-freertos-projects-corrupt-memory
2020-02-19 05:37 AM
Below my compiler configuration:
-ffunction-sections -fdata-sections -Wall -fstack-usage --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
Is it not enough?
2020-10-26 01:40 AM
2020-11-13 09:20 AM
Hello,
I read many topics dealing with the issue concerning float and sprintf, which I have on my CubeIDE project with STM32G474 microcontroller.
_estack definition in the linker file is good: _estack = ORIGIN(RAM) + LENGTH(RAM);
and project option are correct as mentionned previously.
The workaround that correct this issue is simply to remove the _sbrk function definition that can be found within sysmem.c file. It seems to get in conflict with memory management scheme used by FreeRTOS, even if I don't have the exact explanation.
Good luck!
2020-11-14 12:27 AM
Here is an explanation for the heap issues.