commit f06907ce13d6b10c3910f2dbc7fcd6ee00730937 Author: Luca Date: Thu Mar 3 18:30:37 2022 +0100 Initial commit diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..b1dfc17 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,8 @@ +[build] +target = "thumbv6m-none-eabi" + +[target.thumbv6m-none-eabi] +runner = "elf2uf2-rs -d" +rustflags = [ + "-C", "link-arg=-Tlink.x", +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c96eb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4bf4e12 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "pico-test" +version = "0.1.0" +edition = "2018" + +[dependencies] +cortex-m = "0.7.4" +embedded-hal = "0.2.7" +embedded-time = "0.12.1" +panic-halt = "0.2.0" +rp-pico = "0.2.0" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..3fb1eed --- /dev/null +++ b/build.rs @@ -0,0 +1,15 @@ +use std::env; +use std::fs; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + fs::File::create(out_dir.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + + println!("cargo:rustc-link-search={}", out_dir.display()); + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..dfd8540 --- /dev/null +++ b/memory.x @@ -0,0 +1,17 @@ +MEMORY +{ + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + RAM : ORIGIN = 0x20000000, LENGTH = 264K +} + +EXTERN(BOOT2_FIRMWARE) + +SECTIONS +{ + .boot2 ORIGIN(BOOT2) : + { + KEEP(*(.boot2)); + } > BOOT2 +} +INSERT BEFORE .text; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..7761ae3 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,48 @@ +#![no_std] +#![no_main] + +use embedded_hal::digital::v2::OutputPin; + +use embedded_time::fixed_point::FixedPoint; + +use panic_halt as _; + +use rp_pico::Pins; +use rp_pico::entry; +use rp_pico::hal::{Clock, Sio, Watchdog, clocks::init_clocks_and_plls}; +use rp_pico::pac::{CorePeripherals, Peripherals}; + +#[entry] +fn main() -> ! { + let mut p = Peripherals::take().unwrap(); + let cp = CorePeripherals::take().unwrap(); + + let mut watchdog = Watchdog::new(p.WATCHDOG); + let clocks = init_clocks_and_plls( + rp_pico::XOSC_CRYSTAL_FREQ, + p.XOSC, + p.CLOCKS, + p.PLL_SYS, + p.PLL_USB, + &mut p.RESETS, + &mut watchdog + ).ok().unwrap(); + + let sio = Sio::new(p.SIO); + let pins = Pins::new( + p.IO_BANK0, + p.PADS_BANK0, + sio.gpio_bank0, + &mut p.RESETS, + ); + + let mut led = pins.led.into_push_pull_output(); + let mut delay = cortex_m::delay::Delay::new(cp.SYST, clocks.system_clock.freq().integer()); + + loop { + led.set_high().unwrap(); + delay.delay_ms(500); + led.set_low().unwrap(); + delay.delay_ms(500); + } +}