Skip to content

Commit b877b0d

Browse files
committed
Build script now injects EXTI2 => EXTI2_TSC peripheral/interrupt mapping if it's not present in the PAC, removed macro magic in exti that was working around this omission
1 parent 2589d35 commit b877b0d

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

embassy-stm32/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7777
- feat: stm32/flash: add async support for h7 family
7878
- feat: exti brought in line with other drivers' interrupt rebinding system ([#4922](https://github.com/embassy-rs/embassy/pull/4922))
7979
- removal: ExtiInput no longer accepts AnyPin/AnyChannel; AnyChannel removed entirely
80-
- change: build script now generates `unimpl_tsc` cfg option when a chip has a TSC peripheral but no driver
80+
- fix: build script ensures EXTI2_TSC is listed as the IRQ of EXTI2 even if the PAC doesn't
8181
- feat: stm32/lcd: added implementation
8282

8383
## 0.4.0 - 2025-08-26

embassy-stm32/build.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@ fn main() {
5656

5757
eprintln!("chip: {chip_name}");
5858

59-
cfgs.declare("unimpl_tsc");
6059
for p in METADATA.peripherals {
6160
if let Some(r) = &p.registers {
6261
cfgs.enable(r.kind);
6362
foreach_version_cfg(&mut cfgs, r.kind, r.version, |cfgs, cfg_name| {
6463
cfgs.enable(cfg_name);
6564
});
66-
} else if p.name == "TSC" {
67-
//Even if the registers are missing, EXTI needs to know if TSC is present in silicon to know whether the EXTI2 interrupt is shadowed by EXTI2_TSC
68-
cfgs.enable("unimpl_tsc")
6965
}
7066
}
7167

@@ -357,8 +353,13 @@ fn main() {
357353
// ========
358354
// Generate interrupt declarations
359355

356+
let mut exti2_tsc_shared_int_present: Option<stm32_metapac::metadata::Interrupt> = None;
360357
let mut irqs = Vec::new();
361358
for irq in METADATA.interrupts {
359+
// The PAC doesn't ensure this is listed as the IRQ of EXTI2, so we must do so
360+
if irq.name == "EXTI2_TSC" {
361+
exti2_tsc_shared_int_present = Some(irq.clone())
362+
}
362363
irqs.push(format_ident!("{}", irq.name));
363364
}
364365

@@ -1816,7 +1817,19 @@ fn main() {
18161817
for p in METADATA.peripherals {
18171818
let mut pt = TokenStream::new();
18181819

1820+
let mut exti2_tsc_injected = false;
1821+
if let Some(ref irq) = exti2_tsc_shared_int_present
1822+
&& p.name == "EXTI"
1823+
{
1824+
exti2_tsc_injected = true;
1825+
let iname = format_ident!("{}", irq.name);
1826+
let sname = format_ident!("{}", "EXTI2");
1827+
pt.extend(quote!(pub type #sname = crate::interrupt::typelevel::#iname;));
1828+
}
18191829
for irq in p.interrupts {
1830+
if exti2_tsc_injected && irq.signal == "EXTI2" {
1831+
continue;
1832+
}
18201833
let iname = format_ident!("{}", irq.interrupt);
18211834
let sname = format_ident!("{}", irq.signal);
18221835
pt.extend(quote!(pub type #sname = crate::interrupt::typelevel::#iname;));

embassy-stm32/src/exti.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -395,40 +395,30 @@ pub struct AnyChannel {
395395

396396
macro_rules! impl_exti {
397397
($type:ident, $number:expr) => {
398-
impl_exti!(@inner $type, $number, crate::_generated::peripheral_interrupts::EXTI::$type);
399-
};
400-
($type:ident, $number:expr, @tsc) => {
401-
impl_exti!(@inner $type, $number, crate::_generated::peripheral_interrupts::TSC::GLOBAL);
402-
};
403-
(@inner $type:ident, $number:expr, $irq:path) => {
404398
impl SealedChannel for crate::peripherals::$type {}
405399
impl Channel for crate::peripherals::$type {
406400
fn number(&self) -> PinNumber {
407401
$number
408402
}
409403
fn irq(&self) -> InterruptEnum {
410-
<$irq>::IRQ
404+
crate::_generated::peripheral_interrupts::EXTI::$type::IRQ
411405
}
412-
type IRQ = $irq;
406+
type IRQ = crate::_generated::peripheral_interrupts::EXTI::$type;
413407
}
414408

415409
//Still here to surface deprecation messages to the user - remove when removing AnyChannel
416410
#[allow(deprecated)]
417411
impl From<crate::peripherals::$type> for AnyChannel {
418412
fn from(_val: crate::peripherals::$type) -> Self {
419-
Self {
420-
number: $number,
413+
Self { number: $number }
421414
}
422-
}}
415+
}
423416
};
424417
}
425418

426419
impl_exti!(EXTI0, 0);
427420
impl_exti!(EXTI1, 1);
428-
#[cfg(not(any(tsc, unimpl_tsc)))]
429421
impl_exti!(EXTI2, 2);
430-
#[cfg(any(tsc, unimpl_tsc))]
431-
impl_exti!(EXTI2, 2, @tsc);
432422
impl_exti!(EXTI3, 3);
433423
impl_exti!(EXTI4, 4);
434424
impl_exti!(EXTI5, 5);

0 commit comments

Comments
 (0)