cancel
Showing results for 
Search instead for 
Did you mean: 

printf and float

jagauthier
Associate III

So, I'm having an issue getting the printf() function suite to work with floating point values.

First, understand that I am not using STM32CubeIDE. It's a good tool, but I've had too many issues/complications using it. I use a custom Makefile and VScode for my development environment.

That said: With STM32CubeIDE I *can* go into the options and select "Use float with printf from newlib-nano (-u _printf_float)"

This adds "-u _printf_float" to the linker flags and floating point values work.

In My Makefile, I've added "-u _printf_float" to the linker arguments and floating point values are always "0.0".

I'm not sure what else would be causing this.

STM32's linker line versus mine:

arm-none-eabi-gcc -o "CT_ReadG431.elf" @"objects.list"   
-mcpu=cortex-m4 -TSTM32G431KBTx_FLASH.ld
--specs=nosys.specs -Wl,-Map="CT_ReadG431.map" -Wl,--gc-sections -static --specs=nano.specs
 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -Wl,--start-group -lc -lm -Wl,--end-group

Mine:

arm-none-eabi-gccm [Object list omitted for brevity] -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
 -specs=nano.specs -TSTM32G431KBTx_FLASH.ld  -lc -lm -lnosys 
 -Wl,-Map=build/CT_ReadG431.map,--cref -Wl,--gc-sections  -u _printf_float  
 -o build/CT_ReadG431.elf

Could it be something else?

10 REPLIES 10

Well, as far as "buffer", that's how vasprintf() works..

"The functions asprintf() and vasprintf() are analogs of sprintf(3) and vsprintf(3), except that they allocate a string large enough to hold the output including the terminating null byte, and return a pointer to it via the first argument. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed."

As for your other links... I will definitely read those and take them under advisement. I saw you had other posts with similar complaints so I can tell this is a sore spot for you!

Thanks!