#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_halt as _;
#[rtic::app(device = stm32f4xx_hal::pac, peripherals = true)]
mod app {
use stm32f4xx_hal::{
gpio::{gpioa::PA0, gpioc::PC13, Edge, Input, Output, PushPull},
prelude::*,
};
const SYSFREQ: u32 = 100_000_000;
#[shared]
struct Shared {}
#[local]
struct Local {
button: PA0<Input>,
led: PC13<Output<PushPull>>,
}
#[init]
fn init(mut ctx: init::Context) -> (Shared, Local, init::Monotonics) {
let mut syscfg = ctx.device.SYSCFG.constrain();
let rcc = ctx.device.RCC.constrain();
let _clocks = rcc.cfgr.sysclk(SYSFREQ.Hz()).use_hse(25.MHz()).freeze();
let gpioa = ctx.device.GPIOA.split();
let gpioc = ctx.device.GPIOC.split();
let mut button = gpioa.pa0.into_pull_up_input();
button.make_interrupt_source(&mut syscfg);
button.enable_interrupt(&mut ctx.device.EXTI);
button.trigger_on_edge(&mut ctx.device.EXTI, Edge::Falling);
let led = gpioc.pc13.into_push_pull_output();
(
Shared {
},
Local {
button,
led,
},
init::Monotonics(),
)
}
#[idle]
fn idle(_: idle::Context) -> ! {
loop {
continue;
}
}
#[task(binds = EXTI0, local = [button, led])]
fn button_click(ctx: button_click::Context) {
ctx.local.button.clear_interrupt_pending_bit();
ctx.local.led.toggle();
}
}