27 个版本 (17 个稳定版本)

3.1.1 2024 年 8 月 15 日
3.1.0 2024 年 5 月 27 日
3.0.0 2024 年 3 月 13 日
2.1.0 2023 年 10 月 3 日
0.1.2 2020 年 10 月 2 日

11嵌入式开发

Download history 2650/week @ 2024-05-04 2076/week @ 2024-05-11 2143/week @ 2024-05-18 2166/week @ 2024-05-25 1541/week @ 2024-06-01 1238/week @ 2024-06-08 1376/week @ 2024-06-15 1556/week @ 2024-06-22 1821/week @ 2024-06-29 1140/week @ 2024-07-06 1230/week @ 2024-07-13 1430/week @ 2024-07-20 1570/week @ 2024-07-27 1455/week @ 2024-08-03 1557/week @ 2024-08-10 1920/week @ 2024-08-17

6,675 每月下载量
用于 13 包 (3 个直接使用)

MIT/Apache

5.5MB
6.5K SLoC

包含 (ELF 可执行文件/库, 4MB) resources/apps/esp32c6,(ELF 可执行文件/库, 3MB) resources/apps/esp32c2,(ELF 可执行文件/库, 3.5MB) resources/apps/esp32c3,(ELF 可执行文件/库, 3.5MB) resources/apps/esp32h2,(ELF 可执行文件/库, 1.5MB) resources/apps/esp32,(ELF 可执行文件/库, 1.5MB) resources/apps/esp32s2 以及更多

espflash

Crates.io docs.rs MSRV Crates.io

用于烧录 Espressif 设备的库和命令行工具。

支持 ESP32ESP32-C2/C3/C6ESP32-H2ESP32-P4ESP32-S2/S3

目录

安装

如果您是从源代码安装 espflash(即使用 cargo install),则必须在您的系统上安装 rustc>=1.76.0

如果您正在运行 Linux,则还必须安装 libudev;这可以通过大多数流行的软件包管理器获取。如果您正在运行 WindowsmacOS,则可以忽略此步骤。

# Debian/Ubuntu/etc.
apt-get install libudev-dev
# Fedora
dnf install systemd-devel

安装

cargo install espflash

或者,您可以使用 cargo-binstall发布版 下载预编译的工件,并用它们代替

cargo binstall espflash

用法

A command-line tool for flashing Espressif devices

Usage: espflash <COMMAND>

Commands:
  board-info       Print information about a connected target device
  completions      Generate completions for the given shell
  erase-flash      Erase Flash entirely
  erase-parts      Erase specified partitions
  erase-region     Erase specified region
  flash            Flash an application in ELF format to a connected target device
  hold-in-reset    Hold the target device in reset
  monitor          Open the serial monitor without flashing the connected target device
  partition-table  Convert partition tables between CSV and binary format
  read-flash       Read SPI flash content
  reset            Reset the target device
  save-image       Generate a binary application image and save it to a local disk
  write-bin        Write a binary file to a specific address in a target device's flash
  checksum-md5     Calculate the MD5 checksum of the given region
  help             Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Linux 上的权限

在 Linux 中,当使用需要使用串行端口的任何命令时,当前用户可能没有访问串行端口,并可能出现“权限被拒绝”或“端口不存在”错误。

在大多数Linux发行版中,解决方案是将用户添加到dialout组(例如,使用ls -l /dev/ttyUSB0来查找组)的命令,如下所示:sudo usermod -a -G dialout $USER. 使用su - $USER可以启用串口读写权限,而无需注销并重新登录。

请查阅您Linux发行版的文档以获取更多信息。

Windows 子系统 for Linux

目前无法在WSL1中使用espflash。目前没有计划添加对WSL1的支持。

使用WSL2时,也无法使用内置的USB_SERIAL_JTAG外设来烧录芯片,因为复位也会复位USB_SERIAL_JTAG外设,从而将芯片从WSL2断开连接。但是,可以使用WSL2通过UART烧录芯片。

Cargo Runner

您也可以将espflash作为Cargo运行器使用,例如,在项目的.cargo/config.toml文件中添加以下内容:

[target.'cfg(any(target_arch = "riscv32", target_arch = "xtensa"))']
runner = "espflash flash --baud=921600 --monitor /dev/ttyUSB0"

使用此配置,您可以使用cargo run来烧录和监控您的应用程序。

espflash 作为库使用

espflash可以作为库在其他应用程序中使用

espflash = { version = "2.1", default-features = false }

或使用以下命令:cargo add espflash --no-default-features

警告 注意,cli模块不提供SemVer保证。

我们禁用了default-features以禁用默认启用的cli功能;您可能不需要您的应用程序中的任何这些类型或函数,所以没有必要引入额外的依赖项。

配置文件

配置文件允许您定义应用程序的各种参数

  • 串口
    • 按名称
      [connection]
      serial = "/dev/ttyUSB0"
      
    • 按USB VID/PID值
      [[usb_device]]
      vid = "303a"
      pid = "1001"
      
  • 波特率
    baudrate = 460800
    
  • 引导加载程序
    bootloader = "path/to/custom/bootloader.bin"
    
  • 分区表
    partition_table = "path/to/custom/partition-table.bin"
    
  • 闪存设置
    [flash]
    mode = "qio"
    size = "8MB"
    frequency = "80MHz"
    

您可以有本地和/或全局配置文件

  • 对于本地配置,将文件存储在当前工作目录下或在父目录中(以支持Cargo工作区)的espflash.toml名称下
  • 全局文件位置因操作系统而异
    • Linux: $HOME/.config/espflash/espflash.toml
    • macOS: $HOME/Library/Application Support/rs.esp.espflash/espflash.toml
    • Windows: %APPDATA%\esp\espflash\espflash.toml

配置优先级

  1. 环境变量:如果设置了ESPFLASH_PORTESPFLASH_BAUD,则将使用这些值而不是配置文件中的值。
  2. 本地配置文件
  3. 全局配置文件

日志格式

espflashflashmonitor子命令支持使用-L/--log-format参数使用多个日志格式

  • serial:默认日志格式
  • defmt:使用defmt日志框架。使用日志格式,日志字符串具有框架字节来指示它们是defmt消息。
    • 请参阅 defmt 部分esp-println 说明书。
    • 有关如何在 no_std 生态系统中使用 defmt 的详细指南,请参阅 Espressif 书籍上嵌入式 Rust (no_std) 的 defmt 项目

许可证

许可证为以下之一

任选其一。

贡献

除非您明确声明,否则根据 Apache-2.0 许可证定义,您有意提交的任何贡献,均应按上述方式双重许可,不附加任何额外条款或条件。

依赖项

~3–15MB
~206K SLoC