fix(spi): take register block pointer via ptr() instead of regs() - #6051
Merged
Conversation
Manual backport of #6022 to esp-hal-1.1.x. rust-lang/rust#160012 made const evaluation check that a reference is dereferenceable at the point it is created. An MMIO address has no provenance, so initialising `Info` in a `static` through `regs()` no longer compiles: error[E0080]: reference not dereferenceable: reference must be dereferenceable for 244 bytes, but got 0x60024000[noalloc] which is a dangling pointer (it has no provenance) Take the raw pointer via `ptr()` instead, and drop `const` from `regs()` so it cannot be called from const context again. The upstream PR also carries a `cargo fmt` commit that reflows around 79 unrelated files with a newer rustfmt. That commit is deliberately omitted here.
bugadani
approved these changes
Aug 5, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR backports an upstream fix to restore compilation on newer Rust by avoiding creation of MMIO references during const evaluation (which now requires references to be dereferenceable at creation time). It switches SPI instance metadata to store raw register block pointers via ptr() and prevents regs() from being callable in const contexts by removing its const qualifier.
Changes:
- Update SPI master and slave
static INFOinitializers to usecrate::peripherals::$peri::ptr()for the register block. - Change
peripherals::$PERI::regs()frompub const fntopub fnto block const-context usage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| esp-hal/src/spi/slave.rs | Switches slave Info static initialization to use a raw register block pointer (ptr()) instead of creating a reference (regs()) in const context. |
| esp-hal/src/spi/master/mod.rs | Switches master Info static initialization to use a raw register block pointer (ptr()) instead of creating a reference (regs()) in const context. |
| esp-hal/src/peripherals/mod.rs | Makes regs() non-const to prevent future const-eval creation of MMIO references via this helper. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manual backport of #6022 to esp-hal-1.1.x.
rust-lang/rust#160012 made const evaluation check that a reference is dereferenceable at the point it is created. An MMIO address has no provenance, so initialising
Infoin astaticthroughregs()no longer compiles:Take the raw pointer via
ptr()instead, and dropconstfromregs()so it cannot be called from const context again.The upstream PR also carries a
cargo fmtcommit that reflows around 79 unrelated files with a newer rustfmt. That commit is deliberately omitted here.