cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point printf formatting error using ARM GCC newlib-nano on STM32H753

Gpeti
Senior II

I am working on STM32H753 (with eval board EVAL 2).

I am modifying an existing firmware built without libc and without startup files.

I need to convert floating point variables to strings, so I want to use as little as libc as possible. I choosed newlib-nano for memory size.

I compiled with `-mfpu=fpv5-d16 -mfloat-abi=hard -specs=nano.specs ...` and linked with `-mfpu=fpv5-d16 -mfloat-abi=hard -specs=nosys.specs -specs=nano.specs -u _printf_float -nostartfiles ...`

I also added the definition of symbols required by the libc and reserved a memory area for the heap.

 

I tried to write a string from a double variable with the following code (it's code for debug only, I know it may overflow the char array depending on float value):

char my_string[64];
double my_double = 1.3;
sprintf(my_string, "%.3f", my_double);

But the content of the string (checked by dumping the memory on debugger) is `1300` and not `1.300`

(i tried with different values and format specifiers)

Am I missing something ?

4 REPLIES 4
Pavel A.
Super User

What is the version of the toolchain? 

Sorry, it is arm-none-eabi-gcc 10.2.0

Saket_Om
ST Employee

Hello @Gpeti 

Are you using STM32CubeIDE?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

No. I build with make and gcc and I load and debug with Lauterbach trace32