背景:室内環境計測装置(仮)を作って、温度、湿度、CO2は計測していた。が、センサー(SCD41)の仕様により、気圧が計測できていなかった
やりたいこと:I2Cで接続できる気圧センサがあるのでこれをくっつけて気圧も計測する
詳細:
組み込みRustはビルドするまでが結構大変で、時間が経つとどこに環境を作ったのかとか、どうやってビルドしたか?とかかなり忘れている。しょうがないので、GitHubにある、Embedded Rust Trainings for Espressifからstd環境用の入門コードを落としてきて、WSL環境で展開、intro/hardware-checkに入って、cargo buildと打ってみた。大体はビルドできたが、cfg.tomlが無いと怒られたので、exampleからcfg.tomlを複製、自宅のWiFiのSSID等を設定
cp cfg.toml.example cfg.toml
vi cfg.toml
再度トライ、最後のリンカー?のところで、ldproxyが無いと怒られた。これは入れてなかった。以下でインストール
cargo install ldproxy
再度ビルド
cargo build
これでビルドは通った。自分の環境はWSLなので、このままではUSBシリアルで焼けない。そこで、以下でWSLからUSBシリアルに接続できるようにする
PowerShellで実行
usbipd wsl list
usbipd wsl attach --busid 2-1
espflashを使って、Flashにプログラムを書き込む。 espflash monitorでデバッグ出力をウオッチ
cargo espflash board-info
cargo espflash erase-flash
cargo espflash flash
espflash monitor
以下がNeoPixelによるカラフルなLチカ(サンプルコードのまま)
次は、templateをベースにプロジェクトを作ってみる。プロジェクト名は、aq-sensorとする
$ cargo generate --git https://github.com/esp-rs/esp-idf-template cargo
🤷 Project Name: aq_sensor
⚠️ Renaming project called `aq_sensor` to `aq-sensor`...
$ cd aq-sensor/
$ cargo build
ビルドの途中でエラーになって中断。なぜか
ERROR: rust/esp32-c3/aq-sensor/.embuild/espressif/espidf.constraints.v5.1.txt doesn't exist. Perhaps you've forgotten to run the install scripts. Please check the installation guide for more information.
CMake Error at lang/rust/esp32-c3/aq-sensor/.embuild/espressif/esp-idf/v5.1.1/tools/cmake/build.cmake:363 (message):
Some Python dependencies must be installed. Check above message for
details.
espidf.constraints.v5.1.txt doesn't exist.が無いを怒られている?本当に?
エラーメッセージ(.embuild/espressif/esp-idf/v5.1.1/tools/cmake/build.cmake:363 (message):)を頼りに調べると、どうやら以下の、check-python-dependenciesでエラーになっているようであった。これならもう少し調べて不足しているパッケージを足せばビルドが通る!?
idf_build_get_property(python PYTHON)
idf_build_get_property(idf_path IDF_PATH)
message(STATUS "Checking Python dependencies...")
execute_process(COMMAND "${python}" "${idf_path}/tools/idf_tools.py" "check-python-dependencies"
RESULT_VARIABLE result)
if(result EQUAL 1)
# check_python_dependencies returns error code 1 on failure
message(FATAL_ERROR "Some Python dependencies must be installed. Check above message for details.")
elseif(NOT result EQUAL 0)
# means check_python_dependencies.py failed to run at all, result should be an error message
message(FATAL_ERROR "Failed to run Python dependency check. Python: ${python}, Error: ${result}")
endif()
単体で走らせるとこれは問題無いようであった
python3 .espressif/esp-idf/v5.1.2/tools/idf_tools.py check-python-dependencies
Constraint file: /home/sumi/.espressif/espidf.constraints.v5.1.txt
Requirement files:
- .espressif/esp-idf/v5.1.2/tools/requirements/requirements.core.txt
Python being checked: /home/sumi/.espressif/python_env/idf5.1_py3.10_env/bin/python
Python requirements are satisfied.
■追記
WSL上に構築したRustビルド環境はどうも何かパラメータ(オプション設定?)がおかしいようで、cargoによるconfigを行うと最後のesp-idfのビルドでエラーになる。原因を探すより作り直した方が早そうだ。以前、素のUbuntuにRustビルド環境を構築したので、そっちを使ってみた。するとそちらは正常に最後までビルドできた。一方、各種ライブラリのバージョンが上がったせいか 、Flashに乗り切らなくなった。以下のようなエラーが出る
$ cargo espflash --release
New version of cargo-espflash is available: v2.1.0
Serial port: /dev/ttyACM1
Connecting...
Compiling mqtt_tsp_try v0.1.0 (/home/rustbld00/lang/rust/mqtt_tsp_try)
Finished release [optimized] target(s) in 1.92s
Chip type: ESP32-C3 (revision 4)
Crystal frequency: 40MHz
Flash size: 4MB
Features: WiFi
MAC address: 34:85:18:00:b3:ac
App/part. size: 1260720/1048576 bytes, 120.23%
Error:
× Supplied elf image is too big and doesn't fit configured app partition
Flashは4MBあるはずなのに、1.2MBでもう一杯とはどういうことか??と思っていた。すると、これはFlashがパーティションに分割されていて、どうやらデフォルト設定の場合、1MB+α程度らしい。でかいプログラムを乗せたかったらパーティションを切りなおさないといけないらしい。あぁ勉強になる。
■ご参考URL
ESP32: how to read and write the partition table of an ESP device? | mixable Blog
Partition Tables - ESP32-C3 - — ESP-IDF Programming Guide latest documentation
K型熱電対温度計データロガーをESP32-C3(Rust)で作り、InfluxDBで表示する