ESP32-C3 PlatformIO 'embed_txtfiles' 修复
前言
9.9元入手了一块ESP32-C3板子, 用来取代手上引脚不足的ESP8266.
但是编译时候总是失败,从Log上看是这一步出了错误.1
2
3
4
5prepare_file([".pio\build\esp32c3\lite.ttf.txt.o"], ["src\lite.ttf"])
Converting .pio\build\esp32c3\lite.ttf.txt.o
'xtensa-esp32-elf-objcopy' \xb2\xbb\xca\xc7\xc4ڲ\xbf\xbb\xf2\xcdⲿ\xc3\xfc\xc1Ҳ\xb2\xbb\xcaǿ\xc9\xd4\xcb\xd0еij\xcc\xd0\xf2
\xbb\xf2\xc5\xfa\xb4\xa6\xc0\xed\xceļ\xfe\xa1\xa3
*** [.pio\build\esp32c3\lite.ttf.txt.o] Error 1
此外并没有任何提示了.
错误分析
lite.ttf是我的一个放在src目录下的文件,
为其在platformio.ini配置”board_build.embed_txtfiles = src/lite.ttf”,就可以让这个文件嵌入固件中.
从日志里看到是转化的时候出了问题, xtensa-esp32-elf-objcopy
xtensa是ESP32,ESP32-S2,ESP32-S3的处理器结构,而ESP32-C3是RISC-V的,所以这里出错应该是结构不匹配.
去ESP-IDF的文件夹搜索”elf-objcopy”后发现的确有不同很多类似关键字.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19for dir in esp32 esp32s2 esp32c3 esp32s3; do
if [ $dir = esp32 ]; then
TOOLCHAIN="xtensa-esp32-elf"
elif [ $dir = esp32s2 ]; then
TOOLCHAIN="xtensa-esp32s2-elf"
elif [ $dir = esp32c3 ]; then
TOOLCHAIN="riscv32-esp-elf"
elif [ $dir = esp32s3 ]; then
TOOLCHAIN="xtensa-esp32s3-elf"
else
echo "$dir does not exist"
fi
if [ -d "$dir" ]; then
cd $dir
git status libphy.a | grep "modified" >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo $dir/libphy.a fixed
$TOOLCHAIN-objcopy --redefine-sym ets_printf=phy_printf libphy.a
fi
所以应该是PlatformIO在转化的时候调用了错误的程序导致的.
解决问题
去PlatformIO的工作目录(.platformio)下搜索xtensa-esp32-elf-objcopy1
2
3
4
5
6
7
8
9
10
11
12
13[
"xtensa-esp32-elf-objcopy",
"--input-target",
"binary",
"--output-target",
"elf32-xtensa-le",
"--binary-architecture",
"xtensa",
"--rename-section",
".data=.rodata.embedded",
"$SOURCE",
"$TARGET",
]
确实搜索到了多个包含这个关键字的文件_embed_files.py
(platforms\espressif32\builder\frameworks_embed_files.py)
其中platforms下有好几个文件夹
1 | ├── .platformio |
这应该是不同项目所需的platform,凑巧这次C3项目的platform是专门下载的,所以从文件夹修改日期上来看,我这次C3使用的应该是espressif32@src-ebefb4289db63a9f0ca5ee29fa328eef
打开espressif32@src-ebefb4289db63a9f0ca5ee29fa328eef下的_embed_files.py
里面果然还在使用xtensa-esp32-elf-objcopy
按照ESP-IDF里面的描述,应该使用riscv32-esp-elf-objcopy,并且要把xtensa相关的都修改为riscv.
所以最后修改成了
1 | [ |
重新执行编译,这一次终于通过了.1
2
3
4
5
6
7
8
9
10
11
12
13Building in release mode
prepare_file([".pio\build\esp32c3\lite.ttf.txt.o"], ["src\lite.ttf"])
Converting .pio\build\esp32c3\lite.ttf.txt.o
revert_original_file([".pio\build\esp32c3\lite.ttf.txt.o"], ["src\lite.ttf"])
Linking .pio\build\esp32c3\firmware.elf
Retrieving maximum program size .pio\build\esp32c3\firmware.elf
Checking size .pio\build\esp32c3\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 4.7% (used 15480 bytes from 327680 bytes)
Flash: [= ] 14.1% (used 443870 bytes from 3145728 bytes)
Building .pio\build\esp32c3\firmware.bin
esptool.py v3.1
Merged 2 ELF sections
附
_embed_files.py
1 | # Copyright 2014-present PlatformIO <contact@platformio.org> |
环境:
1 | PLATFORM: Espressif 32 (3.3.0+sha.3b5de56) > Espressif ESP32 Dev Module |