Merge pull request #106 from xoviat/fix-exti-new

stm32: fix exti impl. to require dp.SYSCFG.constrain()
This commit is contained in:
xoviat 2021-03-22 13:06:19 -05:00 committed by GitHub
commit 10a77fce14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View File

@ -5,6 +5,30 @@ use cortex_m;
use crate::hal::gpio; use crate::hal::gpio;
#[cfg(any(
feature = "stm32f401",
feature = "stm32f405",
feature = "stm32f407",
feature = "stm32f410",
feature = "stm32f411",
feature = "stm32f412",
feature = "stm32f413",
feature = "stm32f415",
feature = "stm32f417",
feature = "stm32f423",
feature = "stm32f427",
feature = "stm32f429",
feature = "stm32f437",
feature = "stm32f439",
feature = "stm32f446",
feature = "stm32f469",
feature = "stm32f479",
))]
use crate::hal::syscfg::SysCfg;
#[cfg(any(feature = "stm32l0x1", feature = "stm32l0x2", feature = "stm32l0x3",))]
use crate::hal::syscfg::SYSCFG as SysCfg;
use embassy::traits::gpio::{ use embassy::traits::gpio::{
WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge, WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge,
}; };
@ -20,9 +44,9 @@ pub struct ExtiPin<T: Instance> {
} }
impl<T: Instance> ExtiPin<T> { impl<T: Instance> ExtiPin<T> {
pub fn new(mut pin: T, interrupt: T::Interrupt) -> Self { pub fn new(mut pin: T, interrupt: T::Interrupt, syscfg: &mut SysCfg) -> Self {
cortex_m::interrupt::free(|_| { cortex_m::interrupt::free(|_| {
pin.make_source(); pin.make_source(syscfg);
}); });
Self { pin, interrupt } Self { pin, interrupt }
@ -189,7 +213,7 @@ pub trait WithInterrupt: private::Sealed {
} }
pub trait Instance: WithInterrupt { pub trait Instance: WithInterrupt {
fn make_source(&mut self); fn make_source(&mut self, syscfg: &mut SysCfg);
fn clear_pending_bit(&mut self); fn clear_pending_bit(&mut self);
fn trigger_edge(&mut self, edge: EdgeOption); fn trigger_edge(&mut self, edge: EdgeOption);
} }
@ -224,11 +248,9 @@ macro_rules! exti {
feature = "stm32f479", feature = "stm32f479",
))] ))]
impl<T> Instance for gpio::$set::$pin<gpio::Input<T>> { impl<T> Instance for gpio::$set::$pin<gpio::Input<T>> {
fn make_source(&mut self) { fn make_source(&mut self, syscfg: &mut SysCfg) {
use crate::hal::{gpio::Edge, gpio::ExtiPin, syscfg::SysCfg}; use crate::hal::gpio::ExtiPin;
use crate::pac::EXTI; self.make_interrupt_source(syscfg);
let mut syscfg: SysCfg = unsafe { mem::transmute(()) };
self.make_interrupt_source(&mut syscfg);
} }
fn clear_pending_bit(&mut self) { fn clear_pending_bit(&mut self) {
@ -253,7 +275,7 @@ macro_rules! exti {
#[cfg(any(feature = "stm32l0x1", feature = "stm32l0x2", feature = "stm32l0x3",))] #[cfg(any(feature = "stm32l0x1", feature = "stm32l0x2", feature = "stm32l0x3",))]
impl<T> Instance for gpio::$set::$pin<T> { impl<T> Instance for gpio::$set::$pin<T> {
fn make_source(&mut self) {} fn make_source(&mut self, syscfg: &mut SysCfg) {}
fn clear_pending_bit(&mut self) { fn clear_pending_bit(&mut self) {
use crate::hal::{ use crate::hal::{

View File

@ -24,8 +24,9 @@ async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) {
let gpioa = dp.GPIOA.split(); let gpioa = dp.GPIOA.split();
let button = gpioa.pa0.into_pull_up_input(); let button = gpioa.pa0.into_pull_up_input();
let mut syscfg = dp.SYSCFG.constrain();
let pin = ExtiPin::new(button, interrupt::take!(EXTI0)); let pin = ExtiPin::new(button, interrupt::take!(EXTI0), &mut syscfg);
pin_mut!(pin); pin_mut!(pin);
info!("Starting loop"); info!("Starting loop");