Yes, quite easy, stdio.h tells what to do:
hardware/tools/avr/avr/include/stdio.h
Since the full implementation of all the mentioned features becomes
fairly large, three different flavours of vfprintf() can be
selected using linker options. The default vfprintf() implements
all the mentioned functionality except floating point conversions.
A minimized version of vfprintf() is available that only implements
the very basic integer and string conversion facilities, but only
the \c # additional option can be specified using conversion
flags (these flags are parsed correctly from the format
specification, but then simply ignored). This version can be
requested using the following \ref gcc_minusW "compiler options":
\code
-Wl,-u,vfprintf -lprintf_min
\endcode
[color=red]If the full functionality including the floating point conversions
is required, the following options should be used:[/color]
\code
[color=red]-Wl,-u,vfprintf -lprintf_flt -lm[/color]
\endcode
I modified hardware/arduino/avr/platform.txt like this:
## Combine gc-sections, archives, and objects
# -- standard setting with stripped-down printf
# recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm
# -- printf with floating point support
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -Wl,-u,vfprintf -lprintf_flt -lm
Test sketch:
void setup() {
Serial.begin(115200);
Serial.print(F("Sketch: " __FILE__ "\n"
"Compiled: " __DATE__ " " __TIME__ "\n\n"));
char buf[80];
snprintf(buf, sizeof(buf), "%3s %10s %10s %12s", "i", "x", "sin(x)", "exp(x)");
Serial.println(buf);
for (int i = 0; i < 200; i++) {
double x = i * 0.1234;
snprintf(buf, sizeof(buf), "%3d %10.3f %+10.3f %12.5g", i, x, sin(x), exp(x));
Serial.println(buf);
}
}
void loop() { }
Output:
Sketch: test_printf_float.ino
Compiled: Aug 26 2015 22:21:08
i x sin(x) exp(x)
0 0.000 +0.000 1
1 0.123 +0.123 1.1313
2 0.247 +0.244 1.2799
3 0.370 +0.362 1.448
4 0.494 +0.474 1.6382
5 0.617 +0.579 1.8534
6 0.740 +0.675 2.0968
7 0.864 +0.760 2.3722
8 0.987 +0.834 2.6837
9 1.111 +0.896 3.0362
10 1.234 +0.944 3.4349
11 1.357 +0.977 3.8861
12 1.481 +0.996 4.3965
13 1.604 +0.999 4.9739
14 1.728 +0.988 5.6271
15 1.851 +0.961 6.3662
16 1.974 +0.920 7.2023
17 2.098 +0.864 8.1482
18 2.221 +0.796 9.2184
19 2.345 +0.715 10.429
20 2.468 +0.624 11.799
21 2.591 +0.523 13.348
22 2.715 +0.414 15.102
23 2.838 +0.299 17.085
24 2.962 +0.179 19.329
25 3.085 +0.057 21.867
26 3.208 -0.067 24.739
27 3.332 -0.189 27.989
28 3.455 -0.308 31.665
29 3.579 -0.423 35.823
(truncated to stay under 9000 characters)
192 23.693 -0.991 1.9483e+10
193 23.816 -0.968 2.2042e+10
194 23.940 -0.930 2.4937e+10
195 24.063 -0.877 2.8212e+10
196 24.186 -0.811 3.1917e+10
197 24.310 -0.733 3.6109e+10
198 24.433 -0.644 4.0851e+10
199 24.557 -0.545 4.6216e+10