diff --git a/src/main.rs b/src/main.rs index 9a12d44..1f1cef8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,36 +8,61 @@ use cortex_m_rt::entry; use defmt::*; use defmt_rtt as _; use embedded_hal::digital::v2::OutputPin; -use hal::pac; -use hal::sio::Sio; +use embedded_time::fixed_point::FixedPoint; use panic_probe as _; use rp2040_hal as hal; +use hal::{ + clocks::{init_clocks_and_plls, Clock}, + pac, + sio::Sio, + watchdog::Watchdog, +}; + #[link_section = ".boot2"] #[used] pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER; #[entry] fn main() -> ! { + info!("Program start"); let mut pac = pac::Peripherals::take().unwrap(); - - info!("Hello World!"); + let core = pac::CorePeripherals::take().unwrap(); + let mut watchdog = Watchdog::new(pac.WATCHDOG); let sio = Sio::new(pac.SIO); + + // External high-speed crystal on the pico board is 12Mhz + let external_xtal_freq_hz = 12_000_000u32; + let clocks = init_clocks_and_plls( + external_xtal_freq_hz, + pac.XOSC, + pac.CLOCKS, + pac.PLL_SYS, + pac.PLL_USB, + &mut pac.RESETS, + &mut watchdog, + ) + .ok() + .unwrap(); + + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let pins = hal::gpio::Pins::new( pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, &mut pac.RESETS, ); + let mut led_pin = pins.gpio25.into_push_pull_output(); loop { info!("on!"); led_pin.set_high().unwrap(); // TODO: Replace with proper 1s delays once we have clocks working - cortex_m::asm::delay(500_000); + delay.delay_ms(500); info!("off!"); led_pin.set_low().unwrap(); - cortex_m::asm::delay(500_000); + delay.delay_ms(500); } }