From 34519620f3328a25ce37dc1ed8b57fd3d2e2df7b Mon Sep 17 00:00:00 2001 From: Jakob Jungreuthmayer <116195279+jakobjung10@users.noreply.github.com> Date: Sat, 20 Jun 2026 18:08:41 +0200 Subject: [PATCH] fix: read ICSR volatile in SCB::vect_active() `SCB::vect_active()` now reads ICSR with a volatile access, preventing the load from being narrowed to a byte read that faults on word-only ICSR models. --- cortex-m/CHANGELOG.md | 4 ++++ cortex-m/src/peripheral/scb.rs | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cortex-m/CHANGELOG.md b/cortex-m/CHANGELOG.md index 727a3bd0..6c2ae429 100644 --- a/cortex-m/CHANGELOG.md +++ b/cortex-m/CHANGELOG.md @@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - The code should be clippy clean on all supported configurations now. - Add embedded-hal 1.0 delays. +### Fixed +- `SCB::vect_active()` now reads ICSR with a volatile access, preventing the load from being narrowed + to a byte read that faults on word-only ICSR models. + ## [v0.7.7] - 2023-01-03 - Add missing documentation for `critical-section-single-core` feature added diff --git a/cortex-m/src/peripheral/scb.rs b/cortex-m/src/peripheral/scb.rs index 6d9d4700..e98e81d3 100644 --- a/cortex-m/src/peripheral/scb.rs +++ b/cortex-m/src/peripheral/scb.rs @@ -2,7 +2,6 @@ #[cfg(any(armv7m, armv8m))] use core::arch::asm; -use core::ptr; #[cfg(any(armv7m, armv8m))] use core::sync::atomic::{Ordering, compiler_fence}; #[cfg(not(armv6m))] @@ -175,7 +174,7 @@ impl SCB { /// Returns the active exception number #[inline] pub fn vect_active() -> VectActive { - let icsr = unsafe { ptr::read(&(*SCB::PTR).icsr as *const _ as *const u32) }; + let icsr = unsafe { (*SCB::PTR).icsr.read() }; // NOTE(unsafe): Assume correctly selected target. unsafe { VectActive::from(icsr as u8).unwrap_unchecked() }