Skip to content

Commit 7313738

Browse files
authored
Merge pull request #962 from robamu/add-back-cortex-m-irq-gen
add back optional cortex-m interrupt number impl generation
2 parents 540d31e + 26c7236 commit 7313738

6 files changed

Lines changed: 35 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
- { vendor: Spansion, options: "-- --atomics" }
8484
- { vendor: STMicro }
8585
- { vendor: STMicro, options: "-- --atomics" }
86+
- { vendor: STMicro, options: "-- --add-cortex-m-int-num" }
8687
- {
8788
vendor: STMicro,
8889
options: "-- --strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt",

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1010
- Use marker struct instead of address in `Periph` with `PeripheralSpec` trait
1111
- Add `--skip-peripherals-struct` flag to skip generating the `Peripherals`
1212
struct, its `take`/`steal` impl and the `DEVICE_PERIPHERALS` static
13-
- Generated `cortex-m` PACs now implement the `cortex_m_types::InterruptNumber` trait instead
14-
of `cortex-m::interrupt::InterruptNumber` to avoid a hard dependency on `cortex-m` for PACs.
15-
PACs should now use the `cortex-m-types` dependency instead of `cortex-m`.
13+
- Generated `cortex-m` PACs now implement the `cortex_m_types::InterruptNumber` trait instead of
14+
the `cortex-m::interrupt::InterruptNumber` trait. A new `add-cortex-m-int-num` option
15+
which allows adding the generation of the old trait.
1616
- Bump MSRV of generated code to 1.81
1717

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

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct Config {
3838
pub interrupt_link_section: Option<String>,
3939
pub reexport_core_peripherals: bool,
4040
pub reexport_interrupt: bool,
41+
/// Also generating interrupt number trait implementation for `cortex-m` trait.
42+
pub add_cortex_m_int_num: bool,
4143
pub ident_formats: IdentFormats,
4244
pub ident_formats_theme: Option<IdentFormatsTheme>,
4345
pub field_names_for_enums: bool,

src/generate/interrupt.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ pub fn render(
340340
}
341341
}
342342
});
343+
344+
if config.add_cortex_m_int_num {
345+
root.extend(quote! {
346+
unsafe impl cortex_m::interrupt::InterruptNumber for Interrupt {
347+
#[inline(always)]
348+
fn number(#self_token) -> u16 {
349+
#self_token as u16
350+
}
351+
}
352+
});
353+
}
343354
}
344355
Target::XtensaLX => {
345356
root.extend(quote! {

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ Allowed cases are `unchanged` (''), `pascal` ('p'), `constant` ('c') and `snake`
279279
.action(ArgAction::SetTrue)
280280
.help("Reexport interrupt macro from cortex-m-rt like crates"),
281281
)
282+
.arg(
283+
Arg::new("add_cortex_m_int_num")
284+
.long("add-cortex-m-int-num")
285+
.alias("add_cortex_m_int_num")
286+
.action(ArgAction::SetTrue)
287+
.help("Add the generation for the cortex-m InterruptNumber trait impl")
288+
.long_help("Add the generation for the cortex-m InterruptNumber trait impl.
289+
The generated crate will have a dependency on cortex-m.")
290+
)
282291
.arg(
283292
Arg::new("base_address_shift")
284293
.short('b')

svd2rust-regress/src/svd_test.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const CRATES_ALL: &[&str] = &[
1818
const CRATES_MSP430: &[&str] = &["msp430 = \"0.4.0\"", "msp430-rt = \"0.4.0\""];
1919
const CRATES_ATOMICS: &[&str] =
2020
&["portable-atomic = { version = \"1\", default-features = false }"];
21+
const CRATES_CORTEX_M_LEGACY_INT_NUM: &[&str] = &["cortex-m = { version = \"0.7\" }"];
2122
const CRATES_CORTEX_M: &[&str] = &["cortex-m-types = \"0.1\"", "cortex-m-rt = \"0.7\""];
2223
const CRATES_RISCV: &[&str] = &["riscv = \"0.12.1\"", "riscv-rt = \"0.13.0\""];
2324
const CRATES_MIPS: &[&str] = &["mips-mcu = \"0.1.0\""];
@@ -429,15 +430,16 @@ impl TestCase {
429430
Target::XtensaLX => [].iter(),
430431
Target::None => unreachable!(),
431432
})
432-
.chain(if let Some(opts) = opts {
433+
.chain(opts.as_ref().map_or(Vec::new().into_iter(), |opts| {
434+
let mut fragments = Vec::new();
433435
if opts.iter().any(|v| v.contains("atomics")) {
434-
CRATES_ATOMICS.iter()
435-
} else {
436-
[].iter()
436+
fragments.extend(CRATES_ATOMICS);
437437
}
438-
} else {
439-
[].iter()
440-
})
438+
if opts.iter().any(|v| v.contains("add-cortex-m-int-num")) {
439+
fragments.extend(CRATES_CORTEX_M_LEGACY_INT_NUM);
440+
}
441+
fragments.into_iter()
442+
}))
441443
.chain(PROFILE_ALL.iter())
442444
.chain(FEATURES_ALL.iter())
443445
.chain(match &self.arch {

0 commit comments

Comments
 (0)