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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
- { vendor: Spansion, options: "-- --atomics" }
- { vendor: STMicro }
- { vendor: STMicro, options: "-- --atomics" }
- { vendor: STMicro, options: "-- --add-cortex-m-int-num" }
- {
vendor: STMicro,
options: "-- --strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt",
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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`.
- Generated `cortex-m` PACs now implement the `cortex_m_types::InterruptNumber` trait instead of
the `cortex-m::interrupt::InterruptNumber` trait. A new `add-cortex-m-int-num` option
which allows adding the generation of the old trait.
- Bump MSRV of generated code to 1.81

## [v0.37.1] - 2025-10-17
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct Config {
pub interrupt_link_section: Option<String>,
pub reexport_core_peripherals: bool,
pub reexport_interrupt: bool,
/// Also generating interrupt number trait implementation for `cortex-m` trait.
pub add_cortex_m_int_num: bool,
pub ident_formats: IdentFormats,
pub ident_formats_theme: Option<IdentFormatsTheme>,
pub field_names_for_enums: bool,
Expand Down
11 changes: 11 additions & 0 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ pub fn render(
}
}
});

if config.add_cortex_m_int_num {
root.extend(quote! {
unsafe impl cortex_m::interrupt::InterruptNumber for Interrupt {
#[inline(always)]
fn number(#self_token) -> u16 {
#self_token as u16
}
}
});
}
}
Target::XtensaLX => {
root.extend(quote! {
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ Allowed cases are `unchanged` (''), `pascal` ('p'), `constant` ('c') and `snake`
.action(ArgAction::SetTrue)
.help("Reexport interrupt macro from cortex-m-rt like crates"),
)
.arg(
Arg::new("add_cortex_m_int_num")
.long("add-cortex-m-int-num")
.alias("add_cortex_m_int_num")
.action(ArgAction::SetTrue)
.help("Add the generation for the cortex-m InterruptNumber trait impl")
.long_help("Add the generation for the cortex-m InterruptNumber trait impl.
The generated crate will have a dependency on cortex-m.")
)
.arg(
Arg::new("base_address_shift")
.short('b')
Expand Down
16 changes: 9 additions & 7 deletions svd2rust-regress/src/svd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +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_LEGACY_INT_NUM: &[&str] = &["cortex-m = { version = \"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\""];
Expand Down Expand Up @@ -429,15 +430,16 @@ impl TestCase {
Target::XtensaLX => [].iter(),
Target::None => unreachable!(),
})
.chain(if let Some(opts) = opts {
.chain(opts.as_ref().map_or(Vec::new().into_iter(), |opts| {
let mut fragments = Vec::new();
if opts.iter().any(|v| v.contains("atomics")) {
CRATES_ATOMICS.iter()
} else {
[].iter()
fragments.extend(CRATES_ATOMICS);
}
} else {
[].iter()
})
if opts.iter().any(|v| v.contains("add-cortex-m-int-num")) {
fragments.extend(CRATES_CORTEX_M_LEGACY_INT_NUM);
}
fragments.into_iter()
}))
.chain(PROFILE_ALL.iter())
.chain(FEATURES_ALL.iter())
.chain(match &self.arch {
Expand Down
Loading