Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cortex-m/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- `nvic` methods now take `cortex_m_types::InterruptNumber` which is re-exported
as `InterruptNumber`. PACs and HALs need to implement the new trait.

### Removed

- Removed `bare_metal::interrupt::Nr` blanket implementation of `InterruptNumber`
- Removed `bare_metal::interrupt::Nr` re-export inside `interrupt`

### Deprecated

- `interrupt::InterruptNumber`. Implement `cortex_m_types::InterruptNumber` instead.

## [v0.7.10] - 2026-10-21

### Removed
Expand Down
2 changes: 1 addition & 1 deletion cortex-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ links = "cortex-m" # prevent multiple versions of this crate to be linked toget
rust-version = "1.85"

[dependencies]
bare-metal = { version = "0.2.4", features = ["const-fn"] }
critical-section = "1.0.0"
volatile-register = "0.2.2"
bitfield = "0.13.2"
eh0 = { package = "embedded-hal", version = "0.2.4" }
eh1 = { package = "embedded-hal", version = "1.0.0" }
cortex-m-macros = { path = "macros", version = "=0.7.8" }
cortex-m-types = { path = "../cortex-m-types", version = "0.1" }

[dependencies.serde]
version = "1"
Expand Down
20 changes: 15 additions & 5 deletions cortex-m/src/interrupt.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Interrupts

pub use bare_metal::{CriticalSection, Mutex, Nr};
#[cfg(cortex_m)]
use core::arch::asm;
#[cfg(cortex_m)]
use core::sync::atomic::{Ordering, compiler_fence};
use cortex_m_macros::asm_cfg;
use critical_section::CriticalSection;

/// Trait for enums of external interrupt numbers.
///
Expand All @@ -21,19 +21,29 @@ use cortex_m_macros::asm_cfg;
/// and must always return the same value (do not change at runtime).
///
/// These requirements ensure safe nesting of critical sections.
#[deprecated(
since = "0.8.0",
note = "Implement the cortex_m_types::InterruptNumber trait instead"
)]
pub unsafe trait InterruptNumber: Copy {
/// Return the interrupt number associated with this variant.
///
/// See trait documentation for safety requirements.
fn number(self) -> u16;
}

/// Implement InterruptNumber for the old bare_metal::Nr trait.
/// This implementation is for backwards compatibility only and will be removed in cortex-m 0.8.
unsafe impl<T: Nr + Copy> InterruptNumber for T {
// This trait is only here for backwards compatibility.
#[allow(deprecated)]
unsafe impl<T: cortex_m_types::InterruptNumber> InterruptNumber for T {
#[inline]
fn number(self) -> u16 {
self.nr() as u16
const {
assert!(
T::MAX_INTERRUPT_NUMBER <= u16::MAX as usize,
"interrupt numbers must fit into a u16"
)
};
<Self as cortex_m_types::InterruptNumber>::number(self) as u16
}
}

Expand Down
1 change: 0 additions & 1 deletion cortex-m/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
#[cfg(all(feature = "cm7-r0p1", not(armv7em)))]
compile_error!("The feature \"cm7-r0p1\" is only compatible with the armv7em target");

extern crate bare_metal;
extern crate volatile_register;

#[macro_use]
Expand Down
18 changes: 9 additions & 9 deletions cortex-m/src/peripheral/nvic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Nested Vector Interrupt Controller

pub use cortex_m_types::InterruptNumber;
use volatile_register::RW;
#[cfg(not(armv6m))]
use volatile_register::{RO, WO};

use crate::interrupt::InterruptNumber;
use crate::peripheral::NVIC;

/// Register block
Expand Down Expand Up @@ -101,7 +101,7 @@ impl NVIC {
let nr = interrupt.number();

unsafe {
self.stir.write(u32::from(nr));
self.stir.write(nr as u32);
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ impl NVIC {
{
let nr = interrupt.number();
// NOTE(unsafe) atomic read with no side effects
unsafe { (*Self::PTR).ipr[usize::from(nr)].read() }
unsafe { (*Self::PTR).ipr[nr].read() }
}

#[cfg(armv6m)]
Expand Down Expand Up @@ -233,7 +233,7 @@ impl NVIC {
#[cfg(not(armv6m))]
{
let nr = interrupt.number();
self.ipr[usize::from(nr)].write(prio)
self.ipr[nr].write(prio)
}

#[cfg(armv6m)]
Expand Down Expand Up @@ -320,9 +320,9 @@ impl NVIC {
///
/// The `&` helps remove an expensive bounds check - we know all valid interrupt numbers will be in range.
#[inline]
const fn reg_index_and_mask(irq: u16) -> (usize, u32) {
debug_assert!((irq as usize) < (Self::BITMAP_WORDS * 32));
let idx = (irq / 32) as usize & (Self::BITMAP_WORDS - 1);
const fn reg_index_and_mask(irq: usize) -> (usize, u32) {
debug_assert!(irq < (Self::BITMAP_WORDS * 32));
let idx = (irq / 32) & (Self::BITMAP_WORDS - 1);
let mask = 1 << (irq % 32);
(idx, mask)
}
Expand All @@ -333,7 +333,7 @@ impl NVIC {
where
I: InterruptNumber,
{
usize::from(interrupt.number()) / 4
interrupt.number() / 4
}

#[cfg(armv6m)]
Expand All @@ -342,6 +342,6 @@ impl NVIC {
where
I: InterruptNumber,
{
(usize::from(interrupt.number()) % 4) * 8
(interrupt.number() % 4) * 8
}
}
Loading