I am writing a C program for SAM3N arm cortex-M3 microcontroller. When I try to print float numbers, it just prints 'f'.
Example: printf("%f",43.12);
prints f
only, not the 43.12
.
But printing with integers works fine.
How to enable full printing of floats? I know that the compiler, by default, disabled float printing to reduce code size (i.e. seems, they linked cut-down version). Also please note that, there is no CFLAGS=-Dprintf=iprintf
used in makefile.
Tools details:
- ARM/GNU C Compiler : (crosstool-NG 1.13.1 - Atmel build: 13) 4.6.1
- Above tool come with Atmel studio 6.0.
In compilers where floats are disabled by default, it is unusual that the default libraries can handle them. Look through your references and you will find information on how to recompile the appropriate libraries with float support, or (more likely) where to find a version that has already been built with it.
It can be so that your platform/libs does not support
%f
format specifier forprintf/sprintf
. As a first approach you can roll your own printf for floats/doubles:Can you try, adding the below option in linker settings
-lc -lrdimon -u _printf_float
and it worked for me in ARM-CORTEXM0