Arduino 的Serial.print(float)
不打印任何内容。
例如,我修改了tests/sys_arduino/arduino-test.sketch
来测试浮点数,这是差异:
iff --git tests/sys_arduino/arduino-test.sketch tests/sys_arduino/arduino-test.sketch
index 1aa30a9cb..59c2da2c9 100644
--- tests/sys_arduino/arduino-test.sketch
+++ tests/sys_arduino/arduino-test.sketch
@@ -105,6 +105,10 @@ static void print_test(void)
Serial.print("): ");
Serial.println(ul, f);
}
+
+ Serial.print("print(float): ");
+ Serial.print((float)3.14);
+ Serial.println();
}
void loop(void)
2020-10-27 12:03:55,271 # Hello Arduino!
print
2020-10-27 12:03:57,307 # print(int, BIN): 1111101011000111
[...]
2020-10-27 12:03:58,441 # println(unsigned long, HEX): 499602d2
2020-10-27 12:03:58,458 # print(float): 3.14
这是我得到的输出,用 Arduino Uno 测试过:
2020-10-27 12:03:55,271 # Hello Arduino!
print
2020-10-27 12:03:57,307 # print(int, BIN): 1111101011000111
[...]
2020-10-27 12:03:58,441 # println(unsigned long, HEX): 499602d2
2020-10-27 12:03:58,458 # print(float):
Operating System Environment
----------------------------
Operating System: Gentoo
Kernel: Linux 5.4.66-gentoo x86_64 Intel(R) Core(TM) i3-5010U CPU @ 2.10GHz
System shell: GNU bash, version 5.0.18(1)-release (x86_64-pc-linux-gnu)
make's shell: GNU bash, version 5.0.18(1)-release (x86_64-pc-linux-gnu)
Installed compiler toolchains
-----------------------------
native gcc: gcc (Gentoo 9.3.0-r1 p3) 9.3.0
arm-none-eabi-gcc: arm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)
avr-gcc: avr-gcc (Gentoo 9.3.0-r1 p3) 9.3.0
mips-mti-elf-gcc: missing
msp430-elf-gcc: missing
riscv-none-elf-gcc: missing
riscv64-unknown-elf-gcc: missing
riscv-none-embed-gcc: missing
xtensa-esp32-elf-gcc: missing
xtensa-esp8266-elf-gcc: missing
clang: clang version 10.0.1
Installed compiler libs
-----------------------
arm-none-eabi-newlib: "3.3.0"
mips-mti-elf-newlib: missing
msp430-elf-newlib: missing
riscv-none-elf-newlib: missing
riscv64-unknown-elf-newlib: missing
riscv-none-embed-newlib: missing
xtensa-esp32-elf-newlib: missing
xtensa-esp8266-elf-newlib: missing
avr-libc: "2.0.0" ("20150208")
Installed development tools
---------------------------
ccache: missing
cmake: cmake version 3.17.4
cppcheck: Cppcheck 1.88
doxygen: 1.8.17
git: git version 2.26.2
make: GNU Make 4.2.1
openocd: missing
python: Python 3.7.9
python2: Python 2.7.18
python3: Python 3.7.9
flake8: 3.8.1 (mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.7.9 on
coccinelle: missing
@aabadie测试不再适合内存(Arduino Uno),所以我不得不评论上面的几行。 但是,是的,它有效!
测试不再适合内存(Arduino Uno)
奇怪的是,它适合我在 Docker 中构建时(如 #15314 中所述)。 您的 AVR 工具链的版本是什么?
$ avr-g++ --version
avr-g++ (Gentoo 9.3.0-r1 p3) 9.3.0
$ eix-installed -a | grep avr
cross-avr/avr-libc-2.0.0
cross-avr/binutils-2.34-r2
cross-avr/gcc-9.3.0-r1
dev-embedded/avrdude-6.3
好的,所以您的版本比默认的 RIOT 版本更新得多:
$ docker run --rm -ti riot/riotbuild avr-g++ --version
avr-g++ (GCC) 5.4.0
[...]
这解释了我认为代码大小的差异。