diff --git a/src/main.rs b/src/main.rs index 4b3d092..b64dd4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,34 @@ use panic_halt; use cortex_m_rt::entry; -use stm32l4xx_hal::{pac, rcc::RccExt}; +use stm32l4xx_hal::{prelude::*, flash::FlashExt, gpio::GpioExt, pac, pwr::PwrExt, rcc::RccExt, time::Hertz, delay::Delay}; #[entry] fn main() -> ! { let dp = pac::Peripherals::take().unwrap(); let cp = cortex_m::Peripherals::take().unwrap(); - loop {} + let mut flash = dp.FLASH.constrain(); + let mut rcc = dp.RCC.constrain(); + let mut pwr = dp.PWR.constrain(&mut rcc.apb1r1); + + // Ok for now, but ideally actually think about what this does (especially when we have tim). + let clocks = rcc + .cfgr + .hclk(Hertz::MHz(8)) + .freeze(&mut flash.acr, &mut pwr); + + let mut gpioa = dp.GPIOA.split(&mut rcc.ahb2); + let mut led_pin = gpioa + .pa0 + .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper); + + let mut timer = Delay::new(cp.SYST, clocks); + + loop { + timer.delay_ms(1000_u32); + led_pin.set_high(); + timer.delay_ms(1000_u32); + led_pin.set_low(); + } }