embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.16k stars 712 forks source link

How do I bind my own interrupt handling #2392

Open cn-cq-doudou opened 8 months ago

cn-cq-doudou commented 8 months ago

I tried to get wwdg to feed the dog during an early interruption,I follow the embassy-hal-internal/interrupt documentation and use bind_interrupts! Macro and implements the InterruptHandler triat, but it doesn't work.

the code: `static mut WWDG_R: embassy_stm32::pac::wwdg::Wwdg = embassy_stm32::pac::WWDG;

struct InterruptHandler {

} impl interrupt::typelevel::Handler for InterruptHandler { unsafe fn on_interrupt() { WWDG_R.cr().write(|w| { w.set_t(0x7f); }); } } bind_interrupts!(struct Irqs { WWDG => InterruptHandler; });

[entry]

fn main() -> !{ let (p,mut delay) = sys::sys_init(); // Set the external clock info!("Hello World!"); let rcc = embassy_stm32::pac::RCC; rcc.apb1enr().write(|w|{w.set_wwdgen(true)}); let wwdg = embassy_stm32::pac::WWDG; wwdg.cr().write(|w|{ w.set_t(0x7f); w.set_wdga(true); }); wwdg.cfr().write(|w|{ w.set_ewi(true); w.set_w(0x7f); w.set_wdgtb(Wdgtb::DIV8); }); let mut beep = Output::new(p.PF8,Level::High,Speed::High); let mut count = 0; loop { count += 1; if count == 40 { beep.set_low(); } // wwdg.cr().write(|w|{w.set_t(0x7f)}) ; // It works properly when unwrapped delay.delay_ms(40); } }`

votrungchi commented 4 months ago

Hello @cn-cq-doudou Do you have any update on this topic? I am trying to bind the TIM3 timer overflow interrupt to my own handling but dont know how to start. Thank you!