esp32 rust linux

官方文档:https://esp-rs.github.io/book/introduction.html

安装 rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

工具

risc:

复制代码
rustup toolchain install nightly --component rust-src

或使用安装工具同时支持 risc 和 xtensa:

复制代码
cargo install espup

espup install
会在 /home/你的用户名/ 下生成一个 esport-esp.sh,如果要对工程运行 cargo build 或 cargo run 就需要提前引入到命令行里
建议在 ~/.bashrc 的最后新加一行 . $HOME/export-esp.sh

以上都需要:

复制代码
cargo install ldproxy
cargo install cargo-generate

sudo apt install libudev-dev
cargo install espflash

创建模板工程

使用 std 方式,不使用 no_std,std 依赖 esp-idf,但不需要手动下载,会在第一次编译时下载

riscv 和 xtensa 架构的都可以,支持列表看官方文档

复制代码
工程名自己定义,这里以 hhhh 作工程名

xiaguangbo@debian:/media/xiaguangbo/linux_data/project/x/xfoc/project$ cargo generate esp-rs/esp-idf-template cargo
⚠️   Favorite `esp-rs/esp-idf-template` not found in config, using it as a git repository: https://github.com/esp-rs/esp-idf-template.git
🤷   Project Name: hhhh
🔧   Destination: /media/xiaguangbo/linux_data/project/x/xfoc/project/hhhh ...
🔧   project-name: hhhh ...
🔧   Generating template ...
✔ 🤷   Which MCU to target? · esp32c3
✔ 🤷   Configure advanced template options? · true
✔ 🤷   Enable STD support? · true
? 🤷   Configure project to use Dev Containers (VS Code and GitHub Codespaces)? ✔ 🤷   Configure project to use Dev Containers (VS Code and GitHub Codespaces)? · false
? 🤷   Configure project to support Wokwi simulation with Wokwi VS Code extensio✔ 🤷   Configure project to support Wokwi simulation with Wokwi VS Code extension? · false
✔ 🤷   Add CI files for GitHub Action? · false
✔ 🤷   ESP-IDF version (master = UNSTABLE) · master
🔧   Moving generated files into: `/media/xiaguangbo/linux_data/project/x/xfoc/project/hhhh`...
🔧   Initializing a fresh Git repository
✨   Done! New project created /media/xiaguangbo/linux_data/project/x/xfoc/project/hhhh

cd 到工程里

cargo build
第一次会在工程里下载 .embuild/espressif/esp-idf,可能会不断因网络问题失败,再执行。
可能会提示 riscv32-esp-elf-13.2.0_20230928-x86_64-linux-gnu.tar.xz 下载不下来,可以手动下载到 .embuild/espressif/dist 里。
可能会提示 git submodule update --init --recursive,就到 .embuild/espressif/esp-idf/master 里执行一下。

将 esp32c3 连接到电脑上,并把串口的权限改为 777。假设串口是 /dev/ttyUSB0,就执行 sudo chmod 777 /dev/ttyUSB0

cargo run
会让选择是哪个串口,选择对应的串口
会出现 Remember this serial port for future use?,输入 y
就会下载程序到 esp32c3 里并打开串口监控

手动打开串口监控:espflash monitor

cargo run 包含 cargo build 的操作。build 会检查 esp-idf,如果连不上 github/esp...仓库会报错。vscode 的 rust-analyzer 插件也会因这个原因出问题

其他

可能会用到的命令:

复制代码
git submodule update --init --recursive
git clone --recursive --depth 1 --shallow-submodules --branch master https://github.com/espressif/esp-idf.git /media/xiaguangbo/linux_data/project/x/xfoc/project/esp32s3/.embuild/espressif/esp-idf/master
相关推荐
水天需01016 分钟前
shift 命令详解
linux
wdfk_prog16 分钟前
[Linux]学习笔记系列 -- 内核支持与数据
linux·笔记·学习
Coder_Boy_25 分钟前
基于SpringAI的在线考试系统-企业级软件研发工程应用规范实现细节
大数据·开发语言·人工智能·spring boot
lly20240629 分钟前
SQL SELECT 语句详解
开发语言
superman超哥1 小时前
Rust 异步时间管理核心:Tokio 定时器实现机制深度剖析
开发语言·rust·编程语言·rust异步时间管理核心·tokio定时器实现机制·tokio定时器
朔北之忘 Clancy1 小时前
2025 年 9 月青少年软编等考 C 语言一级真题解析
c语言·开发语言·c++·学习·数学·青少年编程·题解
Xの哲學1 小时前
深入剖析Linux文件系统数据结构实现机制
linux·运维·网络·数据结构·算法
玛丽莲茼蒿1 小时前
javaSE 集合框架(五)——java 8新品Stream类
java·开发语言
深圳市恒讯科技1 小时前
Linux 文件权限指南:chmod 755、644、drwxr-xr-x 解析
linux·服务器·xr
wjs20241 小时前
SQLite Glob 子句详解
开发语言