Skip to content

fix(spi): take register block pointer via ptr() instead of regs() - #6051

Merged
MabezDev merged 1 commit into
esp-hal-1.1.xfrom
backport-6022-to-esp-hal-1.1.x
Aug 5, 2026
Merged

fix(spi): take register block pointer via ptr() instead of regs()#6051
MabezDev merged 1 commit into
esp-hal-1.1.xfrom
backport-6022-to-esp-hal-1.1.x

Conversation

@MabezDev

@MabezDev MabezDev commented Aug 5, 2026

Copy link
Copy Markdown
Member

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.

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.
Copilot AI lite review requested due to automatic review settings August 5, 2026 11:08
@MabezDev MabezDev added the skip-changelog No changelog modification needed label Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 INFO initializers to use crate::peripherals::$peri::ptr() for the register block.
  • Change peripherals::$PERI::regs() from pub const fn to pub fn to 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.

@MabezDev
MabezDev merged commit 202566a into esp-hal-1.1.x Aug 5, 2026
40 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog No changelog modification needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants