Skip to content

Instantly share code, notes, and snippets.

Last active Jan 28, 2019
What would you like to do?
static BUTTON: AtomicBool = AtomicBool::new(false);
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);
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);
let mut itm = cp.ITM;
loop {
if BUTTON.load(Ordering::SeqCst) {
iprintln!(&mut itm.stim[0], "Button pushed!");, Ordering::SeqCst);
interrupt!(EXTI0, button_isr);
fn button_isr() {, Ordering::SeqCst);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment