Last active
January 28, 2019 02:14
-
-
Save durka/792b71fd14987ce6d2a0ba887ace4876 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static BUTTON: AtomicBool = AtomicBool::new(false); | |
#[entry] | |
fn main() { | |
let mut cp = cortex_m::Peripherals::take().unwrap(); | |
let dp = stm32f30x::Peripherals::take().unwrap(); | |
let mut flash = dp.FLASH.constrain(); | |
let mut rcc = dp.RCC.constrain(); | |
let clocks = rcc.cfgr.freeze(&mut flash.acr); | |
let delay = Delay::new(cp.SYST, clocks); | |
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb); | |
let button = gpioa.pa0.into_floating_input(&mut gpioa.moder, &mut gpioa.pupdr); | |
cp.NVIC.enable(Interrupt::EXTI0); | |
unsafe { | |
dp.SYSCFG.exticr1.write(|w| w.exti0().bits(0)); // EXTI0 source = PA0 (button) | |
dp.EXTI.imr1.write(|w| w.mr0().set_bit()); // unmask EXTI0 | |
dp.EXTI.ftsr1.write(|w| w.tr0().set_bit()); // trigger on falling edge | |
cp.NVIC.set_priority(Interrupt::EXTI0, 1); | |
NVIC::unpend(Interrupt::EXTI0); | |
} | |
let mut itm = cp.ITM; | |
loop { | |
if BUTTON.load(Ordering::SeqCst) { | |
iprintln!(&mut itm.stim[0], "Button pushed!"); | |
BUTTON.store(false, Ordering::SeqCst); | |
} | |
} | |
} | |
interrupt!(EXTI0, button_isr); | |
fn button_isr() { | |
BUTTON.store(true, Ordering::SeqCst); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment