diff --git a/Cargo.lock b/Cargo.lock index 6a9c681..5e7b695 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -610,6 +610,7 @@ dependencies = [ "embedded-hal-async", "embedded-io-async 0.7.0", "esp-backtrace", + "esp-bootloader-esp-idf", "esp-hal", "esp-println", "esp-rtos", @@ -1085,7 +1086,8 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "esp-backtrace" version = "0.19.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37950e24b2dfd98f1581102d1798281d4d9547af881e6bffc2c2b534c026ec8f" dependencies = [ "cfg-if", "defmt 1.0.1", @@ -1099,10 +1101,29 @@ dependencies = [ "xtensa-lx", ] +[[package]] +name = "esp-bootloader-esp-idf" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ffc117c3a9859835d89d0e90f5ee9886ce2264a71a849a7a22ab5308f6653c" +dependencies = [ + "cfg-if", + "defmt 1.0.1", + "document-features", + "embedded-storage", + "esp-config", + "esp-hal-procmacros", + "esp-metadata-generated", + "esp-rom-sys", + "jiff", + "strum", +] + [[package]] name = "esp-config" version = "0.7.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d9b92fd9cfb0b4f8f1b6219b9763269a335571e307b014903b8201619374b80" dependencies = [ "document-features", "esp-metadata-generated", @@ -1114,7 +1135,8 @@ dependencies = [ [[package]] name = "esp-hal" version = "1.1.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af8fa8216bc126941bd43b5a200a50eab16e43881ccd0dd0b6792f4a82805f0" dependencies = [ "bitfield 0.19.4", "bitflags 2.11.1", @@ -1171,7 +1193,8 @@ dependencies = [ [[package]] name = "esp-hal-procmacros" version = "0.22.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aebfabb2c21bec45e575e4f6cb6bb7aa8e1b33e7ac45b5dffa0f9d33ff59105" dependencies = [ "document-features", "object", @@ -1185,12 +1208,14 @@ dependencies = [ [[package]] name = "esp-metadata-generated" version = "0.4.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42c2ee95b945a4780796e4359e72c033aed3b45073880e8029458f538532db8a" [[package]] name = "esp-println" version = "0.17.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dee1e9ac7c3539bf6464db1707b0edd7557168f98278cf3c84fe70e63c6ce6" dependencies = [ "defmt 1.0.1", "document-features", @@ -1203,7 +1228,8 @@ dependencies = [ [[package]] name = "esp-riscv-rt" version = "0.14.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66a814ae91452de56a5e74f69aebfee40579511756837d3774a56fd24cf0ab79" dependencies = [ "document-features", "riscv", @@ -1213,7 +1239,8 @@ dependencies = [ [[package]] name = "esp-rom-sys" version = "0.1.4" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae852ccb08971155023d1371c96d5490cbc26860f06aee2d629ef73f1a890c3" dependencies = [ "cfg-if", "document-features", @@ -1225,7 +1252,8 @@ dependencies = [ [[package]] name = "esp-rtos" version = "0.3.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "551f90766e1527edaa0c91e8d559e9e2a60397b545e93357ac61fb31845e5712" dependencies = [ "cfg-if", "document-features", @@ -1247,7 +1275,8 @@ dependencies = [ [[package]] name = "esp-sync" version = "0.2.1" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4736bfbbb9e3f6353344e14fc61b6d18d3b877c3286914cf8c0a037be0ed224" dependencies = [ "cfg-if", "document-features", @@ -1550,9 +1579,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hsmc" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3951a3170ce7aa0f0bf4627ac4cc650857f15449c98e97647fa29fcd19c6d33" +checksum = "497ed9593e4baf6ef120b24aff80cb898f6832d32cdf01be9d90be0c06624e77" dependencies = [ "defmt 0.3.100", "embassy-futures", @@ -1564,9 +1593,9 @@ dependencies = [ [[package]] name = "hsmc-macros" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6d97dd1d31fba9e2f96c65c0ce38d7bc1ff59abe775a0ae18e14dfae01d1d1" +checksum = "49d0b1413ed69ba168f9d0edbf4a8ea21569eaf352edf4e11335ae3d765ba004" dependencies = [ "proc-macro2", "quote", @@ -1644,6 +1673,30 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jiff" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00b5dbd620d61dfdcb6007c9c1f6054ebd75319f163d886a9055cec1155073d" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-static" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "keccak" version = "0.1.6" @@ -2058,6 +2111,15 @@ dependencies = [ "critical-section", ] +[[package]] +name = "portable-atomic-util" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" +dependencies = [ + "portable-atomic", +] + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -2927,7 +2989,8 @@ dependencies = [ [[package]] name = "xtensa-lx" version = "0.13.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e012d667b0aa6d2592ace8ef145a98bff3e76cca7a644f4181ecd7a916ed289b" dependencies = [ "critical-section", ] @@ -2935,7 +2998,8 @@ dependencies = [ [[package]] name = "xtensa-lx-rt" version = "0.22.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "409a9b4629d429e995cde4dfbd9fe562ccae66f7624514e200733fc5d0ea8905" dependencies = [ "document-features", "xtensa-lx", @@ -2945,7 +3009,8 @@ dependencies = [ [[package]] name = "xtensa-lx-rt-proc-macros" version = "0.5.0" -source = "git+https://github.com/esp-rs/esp-hal.git?branch=main#54a62c57f1f005020777a4e0843ce03c68312aba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96fb42cd29c42f8744c74276e9f5bee7b06685bbe5b88df891516d72cb320450" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 4ee1d47..ec2d086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,6 @@ homepage = "https://github.com/donglora/firmware" keywords = ["lora", "radio", "embedded", "usb", "firmware"] categories = ["embedded", "hardware-support", "no-std"] -# NOTE: esp-{hal,rtos,backtrace,println} patched from GitHub main (see -# [patch.crates-io] below). The patch versions must stay semver-compatible -# with the version requirements above, or Cargo silently drops the patch -# and falls back to the (older) crates.io release. [dependencies] cfg-if = "1.0" critical-section = "1.2" @@ -65,6 +61,12 @@ esp-println = { version = "0.17", optional = true, features = [ esp-rtos = { version = "0.3", optional = true, features = [ "embassy", ] } +# Emits the IDF app descriptor (`.flash.appdesc`) that espflash v4 +# requires in every ESP binary. The chip subfeature is selected per +# board below alongside the other esp-* chip features. +esp-bootloader-esp-idf = { version = "0.5", optional = true, features = [ + "defmt", +] } # nRF52840 (RAK 4631) cortex-m = { version = "0.7", optional = true, features = [ @@ -146,10 +148,12 @@ heltec_v3 = [ "embassy", "trace-defmt", "dep:esp-backtrace", + "dep:esp-bootloader-esp-idf", "dep:esp-hal", "dep:esp-println", "dep:esp-rtos", "esp-backtrace/esp32s3", + "esp-bootloader-esp-idf/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-rtos/esp32s3", @@ -158,10 +162,12 @@ heltec_v3_uart = [ "embassy", "trace-defmt", "dep:esp-backtrace", + "dep:esp-bootloader-esp-idf", "dep:esp-hal", "dep:esp-println", "dep:esp-rtos", "esp-backtrace/esp32s3", + "esp-bootloader-esp-idf/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-rtos/esp32s3", @@ -170,10 +176,12 @@ heltec_v4 = [ "embassy", "trace-defmt", "dep:esp-backtrace", + "dep:esp-bootloader-esp-idf", "dep:esp-hal", "dep:esp-println", "dep:esp-rtos", "esp-backtrace/esp32s3", + "esp-bootloader-esp-idf/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-rtos/esp32s3", @@ -182,10 +190,12 @@ elecrow_thinknode_m2 = [ "embassy", "trace-defmt", "dep:esp-backtrace", + "dep:esp-bootloader-esp-idf", "dep:esp-hal", "dep:esp-println", "dep:esp-rtos", "esp-backtrace/esp32s3", + "esp-bootloader-esp-idf/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-rtos/esp32s3", @@ -194,10 +204,12 @@ lilygo_tbeam_supreme = [ "embassy", "trace-defmt", "dep:esp-backtrace", + "dep:esp-bootloader-esp-idf", "dep:esp-hal", "dep:esp-println", "dep:esp-rtos", "esp-backtrace/esp32s3", + "esp-bootloader-esp-idf/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-rtos/esp32s3", @@ -206,10 +218,12 @@ lilygo_tbeam = [ "embassy", "trace-defmt", "dep:esp-backtrace", + "dep:esp-bootloader-esp-idf", "dep:esp-hal", "dep:esp-println", "dep:esp-rtos", "esp-backtrace/esp32", + "esp-bootloader-esp-idf/esp32", "esp-hal/esp32", "esp-println/esp32", "esp-rtos/esp32", @@ -250,17 +264,6 @@ waveshare_rp2040_lora = [ "embassy-executor/executor-thread", ] -# REVISIT: pulling esp-{hal,rtos,backtrace,println} from esp-rs/esp-hal main -# to ride ahead of crates.io releases (notably for embassy-executor 0.10 -# support in esp-rtos). When bumping the upstream rev, also bump the version -# requirements above to stay semver-compatible — Cargo silently ignores a -# patch whose version falls outside the requested range. -[patch.crates-io] -esp-hal = { git = "https://github.com/esp-rs/esp-hal.git", branch = "main" } -esp-rtos = { git = "https://github.com/esp-rs/esp-hal.git", branch = "main" } -esp-backtrace = { git = "https://github.com/esp-rs/esp-hal.git", branch = "main" } -esp-println = { git = "https://github.com/esp-rs/esp-hal.git", branch = "main" } - [lints.rust] # hsmc 0.3's `statechart!` macro emits `#[cfg(feature = "journal")]` # attributes (and others). check-cfg evaluates those in the CALLER's diff --git a/TODO.md b/TODO.md index 3cee0fa..d00ec1f 100644 --- a/TODO.md +++ b/TODO.md @@ -33,142 +33,5 @@ Hardware impact: large stability gain on every board — the sx126x BUSY-race fix lands on every nRF/RP2040 board, and the sx127x IRQ-clear fixes unblock TBeam classic in particular. Hardware-verified on Wio Tracker L1 (sx126x): 20/20 clean-boot TX after the fix (vs ~50% -before). - ---- - -## Drop `[patch.crates-io]` + upgrade esp-hal / esp-rtos + add `esp_app_desc!()` + bump espflash to v4 - -Single coordinated change that clears our last remaining dep-graph debt -on the ESP boards. All four pieces are coupled, so they land together. - -### Why - -Today `Cargo.toml` overrides `esp-hal`, `esp-rtos`, `esp-backtrace`, and -`esp-println` with a git pin to `esp-rs/esp-hal#main`. The note in that -block explains the historical reason: - -> REVISIT: esp-rtos 0.2.0 on crates.io pins embassy-executor ^0.9. The -> esp-rs/esp-hal main branch already supports 0.10. Remove these -> patches once esp-rtos publishes a release with embassy-executor 0.10 -> support. - -**That condition is now met.** `esp-rtos 0.3.0` is published on crates.io -and depends on `embassy-executor ^0.10` and `esp-hal ~1.1.0-rc.0` — exactly -what our patches were pulling unofficially. Keeping the patches is no -longer free: it blocks `espflash` v4, blocks `esp-bootloader-esp-idf`, and -ties reproducible builds to whatever commit happens to be on -`esp-rs/esp-hal#main`. - -The immediate trigger is `espflash` v4's required -`esp_bootloader_esp_idf::esp_app_desc!()` check. `save-image` refuses any -ESP binary that lacks the IDF app descriptor. The crate that provides the -macro (`esp-bootloader-esp-idf`) uses the same `esp-rom-sys` native -library as `esp-hal` — two copies of the same `links = "esp_rom_sys"` is -a hard cargo error, so `esp-bootloader-esp-idf` must come from the _same -source_ as `esp-hal`. Easiest way to guarantee that: both from crates.io, -no patches. - -### What changes - -1. **`Cargo.toml`** — delete the entire `[patch.crates-io]` block and the - preceding `REVISIT:` comment. Bump the four esp-rs deps to published - versions: - - `esp-hal = "1.0"` → `"1.1.0-rc.0"` (pre-release selector — see Gotchas) - - `esp-rtos = "0.2"` → `"0.3"` - - `esp-backtrace = "0.18"` → whatever matches esp-rtos 0.3 (check its deps) - - `esp-println = "0.16"` → same - Add a new optional dep + feature wiring for - `esp-bootloader-esp-idf = "0.5"` with `defmt` feature, plus per-board - chip feature (`esp-bootloader-esp-idf/esp32s3` for the S3 boards, - `esp-bootloader-esp-idf/esp32` for LilyGo T-Beam classic). - -2. **`src/main.rs`** — inside the ESP-family branch of the existing - `cfg_if!` block (around line 51), invoke the macro at module scope: - - ```rust - esp_bootloader_esp_idf::esp_app_desc!(); - ``` - - Zero runtime cost. Emits ~256 bytes in `.rodata_desc` with app - metadata (name, version, build date) that the ESP-IDF 2nd-stage - bootloader + `espflash save-image` look for. - -3. **`mise.toml`** — `"cargo:espflash" = "3"` → `"4"`. Drop the deferral - comment on that line. - -4. **Possible API drift fixes** — esp-hal's pre-release versions - occasionally rename or move items. Most likely touch points: - - `src/board/esp32.rs`, `src/board/esp32s3.rs` - - Any board file in `src/board/heltec_*.rs`, `lilygo_*.rs`, - `elecrow_*.rs` that calls into esp-hal / esp-rtos init - Run `just check-all` after steps 1–3 and patch up whatever surfaces. - Don't guess — read the actual compiler errors. - -### How (step by step) - -1. `jj new -m "chore(esp): drop esp-hal patches, bump to published versions, add esp_app_desc!()"` -2. Edit `Cargo.toml` — delete `[patch.crates-io]` + `REVISIT:` comment; - bump the four versions; add `esp-bootloader-esp-idf` dep + feature - wiring for each ESP board feature block. -3. Edit `src/main.rs` — add `esp_bootloader_esp_idf::esp_app_desc!();` - to the ESP branch of the top-level `cfg_if!`. -4. Edit `mise.toml` — espflash `"3"` → `"4"`. -5. `mise install` to pull espflash 4.x. -6. `cargo update` to let the resolver pick a consistent tree with the - new requirements. -7. `just check-all` — expect some compilation errors from API drift on - ESP boards. Fix them one at a time; consult the official examples - in `esp-rs/esp-hal` if in doubt. -8. `just build heltec_v3` (or any ESP board you have) — verify - `espflash save-image` now succeeds end-to-end producing a valid - `.bin`. -9. Flash to real hardware if available. **The RAK4631 and Wio Tracker - L1 (nRF52) boards should be untouched.** - -### Verification - -- `just check-all` clean on all 9 boards. -- `just test` (host-side protocol tests) still green. -- For each ESP board that has been physically validated before - (Heltec V3, LilyGo T-Beam units): flash + confirm radio TX works - end-to-end via ai-bot or a known peer. -- RAK4631 + Wio Tracker L1 unchanged; re-check via `just check` on - both, but no re-flash needed (they don't go through the ESP code - path). - -### Gotchas - -- **Pre-release version selector**: `esp-hal = "1.1.0-rc.0"` by itself - does NOT match pre-release versions in cargo's default semver rules. - Use an exact pre-release like `"1.1.0-rc.0"`, `"~1.1.0-rc.0"` (only - `1.1.0-rc.0`, `1.1.0-rc.1`, … with any patch), or `">=1.1.0-rc.0"`. - `"1.1"` will NOT resolve to a pre-release. -- **Two copies of `esp-rom-sys`**: the root cause of the first failed - attempt at this task. If cargo errors with _"Only one package in the - dependency graph may specify the same links value"_ for - `esp_rom_sys`, it means `esp-hal` and `esp-bootloader-esp-idf` are - being pulled from different sources (one crates.io, one git). Either - both from crates.io (this task's plan) or both from the same git - commit. -- **`esp-bootloader-esp-idf` chip features**: the crate needs exactly - one of `esp32 / esp32s3 / esp32c3 / esp32c6 / …` to be enabled. - Without it, the build panics at its `build.rs`: _"Expected exactly - one of the following features to be enabled: esp32, esp32c2, ..."_. - Wire per-board the same way we wire `esp-hal/esp32s3` etc. -- **Probe-less repro**: `mise install` after bumping espflash to "4" - only installs mise's copy. If the user's global - `~/.cargo/bin/espflash` is stale/different, it still wins on PATH. - The justfile `set shell := ["mise", "exec", "--", "sh", "-c"]` - prepends mise's paths but does NOT reorder `~/.cargo/bin` ahead of - them. Either `cargo uninstall espflash` globally, or change the - justfile recipes to call `$(mise which espflash)` explicitly. - -### Why not now - -Tried it alongside the RAK4631 bring-up in April 2026 and bounced off -the `esp-rom-sys` two-copies problem. Backed out the attempt and left -espflash pinned at v3 + the patches in place so the bring-up commit -stayed atomic and shippable. This task is what's needed to unblock v4 -properly, but it deserves its own focused session — not as -"while-I'm-here" scope on a board bring-up. +before). LilyGo T-Beam classic (sx127x): TX confirmed working +2026-04-30 on the post-esp-hal-1.1 build. diff --git a/mise.toml b/mise.toml index cfc1860..2909eea 100644 --- a/mise.toml +++ b/mise.toml @@ -5,7 +5,7 @@ just = "latest" "cargo:cargo-binutils" = "latest" # rust-objcopy, rust-size "cargo:cargo-hex-to-uf2" = "latest" # ELF → UF2 for nRF52 / RP2040 DFU drives "cargo:espup" = "0.17.1" # ESP Xtensa toolchain installer (pinned: [env] paths below match this version's defaults) -"cargo:espflash" = "3" # flash + save-image for ESP targets (4.x requires esp_app_desc!() in app — revisit alongside esp-hal 1.1+ / drop-the-patches cleanup) +"cargo:espflash" = "4" # flash + save-image for ESP targets "cargo:probe-rs-tools" = "latest" # debug-probe flash/run for ARM targets # Stable Rust + cross-compile targets. Targets land under $RUSTUP_HOME for diff --git a/src/main.rs b/src/main.rs index 0e9c077..1a94b92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,9 @@ cfg_if::cfg_if! { } else if #[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4", feature = "elecrow_thinknode_m2", feature = "lilygo_tbeam_supreme", feature = "lilygo_tbeam"))] { use esp_backtrace as _; use esp_println as _; + // Emits the IDF app descriptor into `.flash.appdesc`. espflash v4 + // refuses any ESP image that lacks it. + esp_bootloader_esp_idf::esp_app_desc!(); } }