Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ jobs:
cargo install svd2rust --path .

# Install the MSRV toolchain
- uses: dtolnay/rust-toolchain@1.76.0
- uses: dtolnay/rust-toolchain@1.81.0
- name: Run reression tool with MSRV
# The MSRV only applies to the generated crate. The regress tool should still be run with
# stable.
run: cargo +stable regress tests --toolchain 1.76.0 -m Nordic -- --strict --atomics
run: cargo +stable regress tests --toolchain 1.81.0 -m Nordic -- --strict --atomics

ci-docs-clippy:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- Use marker struct instead of address in `Periph` with `PeripheralSpec` trait
- Add `--skip-peripherals-struct` flag to skip generating the `Peripherals`
struct, its `take`/`steal` impl and the `DEVICE_PERIPHERALS` static
- Generated `cortex-m` PACs now implement the `cortex_m_types::InterruptNumber` trait instead
of `cortex-m::interrupt::InterruptNumber` to avoid a hard dependency on `cortex-m` for PACs.
PACs should now use the `cortex-m-types` dependency instead of `cortex-m`.
- Bump MSRV of generated code to 1.81

## [v0.37.1] - 2025-10-17

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ This project is developed and maintained by the [Tools team][team].

## Minimum Supported Rust Version (MSRV)

The **generated code** is guaranteed to compile on stable Rust 1.76.0 and up.
The **generated code** is guaranteed to compile on stable Rust 1.81.0 and up.

If you encounter compilation errors on any stable version newer than 1.76.0, please open an issue.
If you encounter compilation errors on any stable version newer than 1.81.0, please open an issue.

# Testing Locally

Expand Down
43 changes: 32 additions & 11 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn render(
(quote!(#[no_mangle]), quote!(extern))
};

let n = util::unsuffixed(pos);
let num_of_interrupts = util::unsuffixed(pos);
match target {
Target::CortexM => {
for name in &names {
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn render(
#[doc(hidden)]
#link_section_attr
#nomangle
pub static __INTERRUPTS: [Vector; #n] = [
pub static __INTERRUPTS: [Vector; #num_of_interrupts] = [
#elements
];
});
Expand Down Expand Up @@ -193,7 +193,7 @@ pub fn render(
#nomangle
#[used]
pub static __INTERRUPTS:
[Vector; #n] = [
[Vector; #num_of_interrupts] = [
#elements
];
});
Expand Down Expand Up @@ -228,7 +228,7 @@ pub fn render(
#[doc(hidden)]
#link_section_attr
#nomangle
pub static __EXTERNAL_INTERRUPTS: [Vector; #n] = [
pub static __EXTERNAL_INTERRUPTS: [Vector; #num_of_interrupts] = [
#elements
];
});
Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn render(
#[doc(hidden)]
#link_section_attr
#nomangle
pub static __INTERRUPTS: [Vector; #n] = [
pub static __INTERRUPTS: [Vector; #num_of_interrupts] = [
#elements
];
});
Expand All @@ -273,10 +273,10 @@ pub fn render(
}

let self_token = quote!(self);
let (enum_repr, nr_expr) = if variants.is_empty() {
(quote!(), quote!(match #self_token {}))
let enum_repr = if variants.is_empty() {
quote!()
} else {
(quote!(#[repr(u16)]), quote!(#self_token as u16))
quote!(#[repr(u16)])
};

let defmt = config
Expand Down Expand Up @@ -309,13 +309,34 @@ pub fn render(

match target {
Target::CortexM => {
let num_value: usize = num_of_interrupts.base10_parse()?;
let max_interrupt_number = num_value.saturating_sub(1);

root.extend(quote! {
#interrupt_enum

unsafe impl cortex_m::interrupt::InterruptNumber for Interrupt {
unsafe impl cortex_m_types::InterruptNumber for Interrupt {
const MAX_INTERRUPT_NUMBER: usize = #max_interrupt_number;

#[inline(always)]
fn number(#self_token) -> u16 {
#nr_expr
fn number(#self_token) -> usize {
#self_token as usize
}

/// Tries to convert a number to a valid interrupt.
#[inline]
fn from_number(value: usize) -> cortex_m_types::result::Result<Self> {
if value > Self::MAX_INTERRUPT_NUMBER {
return Err(cortex_m_types::result::Error::IndexOutOfBounds {
index: value,
min: 0,
max: Self::MAX_INTERRUPT_NUMBER,
});
}
match value {
#from_arms
_ => Err(cortex_m_types::result::Error::InvalidVariant(value)),
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
//! ``` toml
//! [dependencies]
//! critical-section = { version = "1.0", optional = true }
//! cortex-m = "0.7.6"
//! cortex-m-types = "0.1"
//! cortex-m-rt = { version = "0.6.13", optional = true }
//! vcell = "0.1.2"
//!
Expand Down
2 changes: 1 addition & 1 deletion svd2rust-regress/src/svd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CRATES_ALL: &[&str] = &[
const CRATES_MSP430: &[&str] = &["msp430 = \"0.4.0\"", "msp430-rt = \"0.4.0\""];
const CRATES_ATOMICS: &[&str] =
&["portable-atomic = { version = \"1\", default-features = false }"];
const CRATES_CORTEX_M: &[&str] = &["cortex-m = \"0.7.6\"", "cortex-m-rt = \"0.7\""];
const CRATES_CORTEX_M: &[&str] = &["cortex-m-types = \"0.1\"", "cortex-m-rt = \"0.7\""];
const CRATES_RISCV: &[&str] = &["riscv = \"0.12.1\"", "riscv-rt = \"0.13.0\""];
const CRATES_MIPS: &[&str] = &["mips-mcu = \"0.1.0\""];
const PROFILE_ALL: &[&str] = &["[profile.dev]", "incremental = false"];
Expand Down
Loading