说在前面
- esp型号:esp32s3
- 开发环境:wsl2
- rustc版本:rustc 1.73.0-nightly
- esp idf版本:v5.1.1
流程
- 目前是按照这个demo的流程可以跑通
- 修改demo中的部分代码,不然可能跑不通
~/rust-esp32-std-demo$ git diff src/main.rs diff --git a/src/main.rs b/src/main.rs index da6e581..f6f9aeb 100644 --- a/src/main.rs +++ b/src/main.rs -const SSID: &str = env!("RUST_ESP32_STD_DEMO_WIFI_SSID"); +const SSID: &str = "修改为wifi名"; -const PASS: &str = env!("RUST_ESP32_STD_DEMO_WIFI_PASS"); +const PASS: &str = "修改为wifi密码"; #[cfg(esp32s2)] include!(env!("EMBUILD_GENERATED_SYMBOLS_FILE")); @@ -510,7 +510,7 @@ fn test_fs() -> Result<()> { fn test_tcp() -> Result<()> { info!("About to open a TCP connection to 1.1.1.1 port 80"); - let mut stream = TcpStream::connect("one.one.one.one:80")?; + let mut stream = TcpStream::connect("223.5.5.5:80")?; // 国内dns let err = stream.try_clone(); if let Err(err) = err { @@ -827,12 +827,12 @@ fn test_https_client() -> anyhow::Result<()> { - let addr = "google.com:443".to_socket_addrs()?.next().unwrap(); + let addr = "baidu.com:443".to_socket_addrs()?.next().unwrap(); //你懂的 let socket = Async::<TcpStream>::connect(addr).await?; let mut tls = esp_idf_svc::tls::AsyncEspTls::adopt(EspTlsSocket::new(socket))?; - tls.negotiate("google.com", &esp_idf_svc::tls::Config::new()) + tls.negotiate("baidu.com", &esp_idf_svc::tls::Config::new()) //你懂的 .await?; tls.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;
可能的问题
- 以下这些问题奇奇怪怪,主要可能还是
rust toolchain
没有安装对 - 还有就是按照rust build中
espup
的流程执行之后,我还是继续执行了./install-rust-toolchain.sh
,不知道哪里有问题
wsl2相关
- 如何访问usb设备
Connect USB devices
rust相关
-
lib
cargo install cargo-generate cargo install ldproxy cargo install espup cargo install espflash cargo install cargo-espflash # Optional
-
问题:
cargo-generate
缺少pkg-config
run pkg_config fail: Could not run `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" "pkg-config" "--libs" "--cflags" "openssl"` The pkg-config command could not be found. Most likely, you need to install a pkg-config package for your OS. Try `apt install pkg-config`, or `yum install pkg-config`, or `pkg install pkg-config`, or `apk add pkgconfig` depending on your distribution.
解决:
apt install pkg-config
-
问题:
espflash
缺少libudev
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "`PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=\"1\" PKG_CONFIG_ALLOW_SYSTEM_LIBS=\"1\" \"pkg-config\" \"--libs\" \"-- cflags\" \"libudev\"` did not exit successfully: exit status: 1\nerror: could not find system library 'libudev' required by the 'libudev-sys' crate\n\n--- stderr\nPackage libudev was not found in the pkg-config search path.\n Perhaps you should add the directory containing `libudev.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'libudev' found\n"',
解决:
apt install libudev-dev
-
espup
这里 -
缺少
xtensa-esp32-espidf
文章来源:https://www.toymoban.com/news/detail-719407.htmlerror: Error loading target specification: Could not find specification for target "xtensa-esp32-espidf". Run `rustc --print target-list` for a list of built-in targets
解决:文章来源地址https://www.toymoban.com/news/detail-719407.html
rustup default esp
vscode相关
- 插件(可选)
这里 - 在初始化的时候由于需要访问到github,这里可以设置下proxy:
- 缺少venv
sudo apt install python3.10-venv
build相关
- 缺少
libclang
解决:主要还是thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-.so', 'libclang.so.', 'libclang-.so.'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: [])"'
rust build
没有搞好,如果已经搞好了,则需要设置一下环境变量~/rust-build$ . export-esp.sh
- 未识别到
xtensa
解决error: unknown target triple 'xtensa', please use -triple or -arch
rustup update git clone git@github.com:esp-rs/rust-build.git chmod +x install-rust-toolchain.sh ./install-rust-toolchain.sh -i reinstall # this can probably fail the first time, so then softwareupdate --all --install --force ./install-rust-toolchain.sh -i reinstall
- 选择target
这里我使用的是$ rustc --print target-list xtensa-esp32-espidf xtensa-esp32-none-elf xtensa-esp32s2-espidf xtensa-esp32s2-none-elf xtensa-esp32s3-espidf xtensa-esp32s3-none-elf xtensa-esp8266-none-elf
xtensa-esp32s3-espidf
- 每次更改了依赖之后,build都会重下
esp-idf
解决:在首次安装好esp-idf后将IDF_PATH
环境变量设置好
同样,也可以将vi ~/.bashrc # 并将下述语句添加到文件最后 下述路径即esp-idf的安装路径 自行更改 export IDF_PATH="/home/le/.espressif/esp-idf/v5.1.1"
rust-build
里export-esp.sh
的LIBCLANG_PATH
和PATH
加进去
测试
- flash
~/rust-esp32-std-demo$ espflash flash target/xtensa-esp32s3-espidf/debug/rust-esp32-std-demo [2023-10-26T16:39:10Z INFO ] Serial port: '/dev/ttyACM0' [2023-10-26T16:39:10Z INFO ] Connecting... [2023-10-26T16:39:11Z INFO ] Using flash stub Chip type: esp32s3 (revision v0.1) Crystal frequency: 40MHz Flash size: 16MB Features: WiFi, BLE MAC address: App/part. size: 1,763,504/16,384,000 bytes, 10.76% [00:00:01] [========================================] 14/14 0x0 [00:00:00] [========================================] 1/1 0x8000 [00:01:41] [========================================] 1016/1016 0x10000 [2023-10-26T16:40:55Z INFO ] Flashing has completed!
- monitor
~/rust-esp32-std-demo$ espflash monitor [2023-10-26T16:41:43Z INFO ] Serial port: '/dev/ttyACM0' [2023-10-26T16:41:43Z INFO ] Connecting... [2023-10-26T16:41:44Z INFO ] Using flash stub Commands: CTRL+R Reset chip CTRL+C Exit I (31) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader I (32) boot: compile time Jun 7 2023 08:07:32 I (33) boot: Multicore bootloader I (37) boot: chip revision: v0.1 I (41) boot.esp32s3: Boot SPI Speed : 40MHz I (46) boot.esp32s3: SPI Mode : DIO I (50) boot.esp32s3: SPI Flash Size : 16MB I (55) boot: Enabling RNG early entropy source... ... I (18144) rust_esp32_std_demo: Wifi DHCP info: IpInfo { ip: 192.168.1.11, subnet: Subnet { gateway: 192.168.1.1, mask: Mask(24) }, dns: Some(192.168.1.1), secondary_dns: Some(0.0.0.0) } ...
- 访问
monitor
信息中的ip地址
吐槽
也许我打开方式不对,太恶心了,在试错的时候每次build
都重新下一遍esp idf
,解决方式见上
参考
- rust build
- rust-esp32-std-demo
- The Rust on ESP Book
- esp-idf-template
- Using esp-idf-sys without downloading anything
到了这里,关于【rust/esp32】wsl2开发环境搭建与测试的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!