mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-12 05:21:31 +11:00
ffa97842e2
* Improve clock frequency stuff for uninitialized clocks - Made clocks singletons so the frequency handling actually works as expected - Added initial frequencies - Improved the docs - Added a Clock trait * Add pico examples. These have the benefit of knowing which external crystal is attached. Even though it always should be a 12 MHz crystal. Thus we can setup the clocks properly I also changed the rp2040 examples to work out of the box for pico boards since that will probably be used most of the time
61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
//! Blinks the LED on a Pico board
|
|
//!
|
|
//! This will blink an LED attached to GP25, which is the pin the Pico uses for the on-board LED.
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use cortex_m_rt::entry;
|
|
use embedded_hal::digital::v2::OutputPin;
|
|
use embedded_time::rate::*;
|
|
use panic_halt as _;
|
|
use pico::{
|
|
hal::{
|
|
clocks::{init_clocks_and_plls, Clock},
|
|
pac,
|
|
sio::Sio,
|
|
watchdog::Watchdog,
|
|
},
|
|
Pins, XOSC_CRYSTAL_FREQ,
|
|
};
|
|
#[link_section = ".boot2"]
|
|
#[used]
|
|
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
|
let core = pac::CorePeripherals::take().unwrap();
|
|
|
|
let mut watchdog = Watchdog::new(pac.WATCHDOG);
|
|
|
|
let clocks = init_clocks_and_plls(
|
|
XOSC_CRYSTAL_FREQ,
|
|
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 sio = Sio::new(pac.SIO);
|
|
let pins = Pins::new(
|
|
pac.IO_BANK0,
|
|
pac.PADS_BANK0,
|
|
sio.gpio_bank0,
|
|
&mut pac.RESETS,
|
|
);
|
|
let mut led_pin = pins.led.into_push_pull_output();
|
|
|
|
loop {
|
|
led_pin.set_high().unwrap();
|
|
delay.delay_ms(500);
|
|
led_pin.set_low().unwrap();
|
|
delay.delay_ms(500);
|
|
}
|
|
}
|