diff options
| -rw-r--r-- | embassy-stm32/gen.py | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/exti.rs | 71 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 2 |
3 files changed, 43 insertions, 46 deletions
diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 97773bb45..5ba05fa3a 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py | |||
| @@ -57,6 +57,7 @@ for chip in chips.values(): | |||
| 57 | 57 | ||
| 58 | af = gpio_afs[chip['gpio_af']] | 58 | af = gpio_afs[chip['gpio_af']] |
| 59 | peripheral_names = [] # USART1, PA5, EXTI8 | 59 | peripheral_names = [] # USART1, PA5, EXTI8 |
| 60 | exti_interrupts = [] # EXTI IRQs, EXTI0, EXTI4_15 etc. | ||
| 60 | peripheral_versions = {} # usart -> v1, syscfg -> f4 | 61 | peripheral_versions = {} # usart -> v1, syscfg -> f4 |
| 61 | pins = set() # set of all present pins. PA4, PA5... | 62 | pins = set() # set of all present pins. PA4, PA5... |
| 62 | 63 | ||
| @@ -177,6 +178,12 @@ for chip in chips.values(): | |||
| 177 | if func := funcs.get(f'{name}_D7'): | 178 | if func := funcs.get(f'{name}_D7'): |
| 178 | f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});') | 179 | f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});') |
| 179 | 180 | ||
| 181 | |||
| 182 | if block_mod == 'exti': | ||
| 183 | for irq in chip['interrupts']: | ||
| 184 | if re.match('EXTI', irq): | ||
| 185 | exti_interrupts.append(irq) | ||
| 186 | |||
| 180 | if not custom_singletons: | 187 | if not custom_singletons: |
| 181 | peripheral_names.append(name) | 188 | peripheral_names.append(name) |
| 182 | 189 | ||
| @@ -228,6 +235,15 @@ for chip in chips.values(): | |||
| 228 | }} | 235 | }} |
| 229 | 236 | ||
| 230 | {''.join(irq_declares)} | 237 | {''.join(irq_declares)} |
| 238 | |||
| 239 | pub mod exti {{ | ||
| 240 | use embassy::interrupt::InterruptExt; | ||
| 241 | use crate::interrupt; | ||
| 242 | use super::*; | ||
| 243 | |||
| 244 | impl_exti_irq!({','.join(exti_interrupts)}); | ||
| 245 | impl_exti_init!({','.join(exti_interrupts)}); | ||
| 246 | }} | ||
| 231 | }} | 247 | }} |
| 232 | mod interrupt_vector {{ | 248 | mod interrupt_vector {{ |
| 233 | extern "C" {{ | 249 | extern "C" {{ |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 0ae121cea..9f2401c89 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -21,41 +21,6 @@ const EXTI_COUNT: usize = 16; | |||
| 21 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 21 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 22 | static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [NEW_AW; EXTI_COUNT]; | 22 | static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [NEW_AW; EXTI_COUNT]; |
| 23 | 23 | ||
| 24 | #[interrupt] | ||
| 25 | unsafe fn EXTI0() { | ||
| 26 | on_irq() | ||
| 27 | } | ||
| 28 | |||
| 29 | #[interrupt] | ||
| 30 | unsafe fn EXTI1() { | ||
| 31 | on_irq() | ||
| 32 | } | ||
| 33 | |||
| 34 | #[interrupt] | ||
| 35 | unsafe fn EXTI2() { | ||
| 36 | on_irq() | ||
| 37 | } | ||
| 38 | |||
| 39 | #[interrupt] | ||
| 40 | unsafe fn EXTI3() { | ||
| 41 | on_irq() | ||
| 42 | } | ||
| 43 | |||
| 44 | #[interrupt] | ||
| 45 | unsafe fn EXTI4() { | ||
| 46 | on_irq() | ||
| 47 | } | ||
| 48 | |||
| 49 | #[interrupt] | ||
| 50 | unsafe fn EXTI9_5() { | ||
| 51 | on_irq() | ||
| 52 | } | ||
| 53 | |||
| 54 | #[interrupt] | ||
| 55 | unsafe fn EXTI15_10() { | ||
| 56 | on_irq() | ||
| 57 | } | ||
| 58 | |||
| 59 | pub unsafe fn on_irq() { | 24 | pub unsafe fn on_irq() { |
| 60 | let bits = EXTI.pr().read().0; | 25 | let bits = EXTI.pr().read().0; |
| 61 | 26 | ||
| @@ -249,14 +214,30 @@ impl_exti!(EXTI13, 13); | |||
| 249 | impl_exti!(EXTI14, 14); | 214 | impl_exti!(EXTI14, 14); |
| 250 | impl_exti!(EXTI15, 15); | 215 | impl_exti!(EXTI15, 15); |
| 251 | 216 | ||
| 252 | /// safety: must be called only once | 217 | macro_rules! impl_exti_irq { |
| 253 | pub(crate) unsafe fn init() { | 218 | ($e:ident) => { |
| 254 | interrupt::EXTI0::steal().enable(); | 219 | #[interrupt] |
| 255 | interrupt::EXTI1::steal().enable(); | 220 | unsafe fn $e() { |
| 256 | interrupt::EXTI2::steal().enable(); | 221 | crate::exti::on_irq() |
| 257 | interrupt::EXTI3::steal().enable(); | 222 | } |
| 258 | interrupt::EXTI4::steal().enable(); | 223 | }; |
| 259 | interrupt::EXTI9_5::steal().enable(); | 224 | |
| 260 | interrupt::EXTI15_10::steal().enable(); | 225 | ($e:ident, $($es:ident),+) => { |
| 261 | interrupt::EXTI15_10::steal().enable(); | 226 | impl_exti_irq! { $e } |
| 227 | impl_exti_irq! { $($es),+ } | ||
| 228 | }; | ||
| 229 | } | ||
| 230 | |||
| 231 | macro_rules! impl_exti_init { | ||
| 232 | ($e:ident) => { | ||
| 233 | crate::interrupt::$e::steal().enable(); | ||
| 234 | }; | ||
| 235 | |||
| 236 | ($e:ident, $($es:ident),+) => { | ||
| 237 | /// safety: must be called only once | ||
| 238 | pub(crate) unsafe fn init() { | ||
| 239 | impl_exti_init! { $e } | ||
| 240 | impl_exti_init! { $($es),+ } | ||
| 241 | } | ||
| 242 | }; | ||
| 262 | } | 243 | } |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index edb90d779..0751ac0b6 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -49,8 +49,8 @@ pub fn init(_config: Config) -> Peripherals { | |||
| 49 | let p = Peripherals::take(); | 49 | let p = Peripherals::take(); |
| 50 | 50 | ||
| 51 | unsafe { | 51 | unsafe { |
| 52 | exti::init(); | ||
| 53 | dma::init(); | 52 | dma::init(); |
| 53 | interrupt::exti::init(); | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | p | 56 | p |
