Set up the demo blinky app with a pi pico

This commit is contained in:
Savanni D'Gerinel 2024-08-01 10:00:22 -04:00
parent 98ceab9833
commit 506a13e802
7 changed files with 742 additions and 147 deletions

775
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +0,0 @@
[build]
target = "thumbv6m-none-eabi"
[target.thumbv6m-none-eabi]
rustflags = [
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
]
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"

View File

@ -0,0 +1,6 @@
[build]
target = "thumbv6m-none-eabi"
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"

View File

@ -5,11 +5,14 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
az = { version = "1" } embassy-embedded-hal = { version = "0.1.0", features = ["defmt"] }
cortex-m-rt = { version = "0.7.3" } embassy-sync = { version = "0.6.0", features = ["defmt"] }
cortex-m = { version = "0.7.7" } embassy-executor = { version = "0.5.0", features = ["task-arena-size-98304", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
embedded-alloc = { version = "0.5.1" } embassy-time = { version = "0.3.1", features = ["defmt", "defmt-timestamp-uptime"] }
embedded-hal = { version = "0.2.7" } embassy-rp = { version = "0.1.0", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl"] }
panic-halt = { version = "0.2.0" }
rp-pico = { version = "0.8.0" }
defmt = "0.3"
defmt-rtt = "0.4"
cortex-m-rt = "0.7.0"
panic-probe = { version = "0.3", features = ["print-defmt"] }

View File

@ -4,11 +4,23 @@ use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
fn main() { fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x")) File::create(out.join("memory.x"))
.unwrap() .unwrap()
.write_all(include_bytes!("memory.x")) .write_all(include_bytes!("memory.x"))
.unwrap(); .unwrap();
println!("cargo:rustc-link-search={}", out.display()); println!("cargo:rustc-link-search={}", out.display());
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x"); println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
} }

View File

@ -5,55 +5,26 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use cortex_m::delay::Delay; use embassy_executor::Spawner;
use embedded_hal::digital::v2::OutputPin; use embassy_rp::gpio;
use panic_halt as _; use embassy_time::Timer;
use rp_pico::{ use gpio::{Level, Output};
entry, use defmt::*;
hal::{ use defmt_rtt as _;
clocks::init_clocks_and_plls, use panic_probe as _;
pac::{CorePeripherals, Peripherals},
watchdog::Watchdog,
Clock, Sio,
},
Pins,
};
#[entry] #[embassy_executor::main]
fn main() -> ! { async fn main(_spawner: Spawner) {
let mut pac = Peripherals::take().unwrap(); let p = embassy_rp::init(Default::default());
let core = CorePeripherals::take().unwrap(); let mut led = Output::new(p.PIN_25, Level::Low);
let sio = Sio::new(pac.SIO);
let pins = Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let mut watchdog = Watchdog::new(pac.WATCHDOG);
let clocks = init_clocks_and_plls(
12_000_000u32,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();
let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
let mut led_pin = pins.led.into_push_pull_output();
let delay_ms = 1000;
loop { loop {
let _ = led_pin.set_high(); info!("led on!");
delay.delay_ms(delay_ms); led.set_high();
Timer::after_secs(1).await;
let _ = led_pin.set_low(); info!("led off!");
delay.delay_ms(delay_ms); led.set_low();
Timer::after_secs(1).await;
} }
} }

View File

@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "1.77.0" channel = "1.80.0"
targets = [ "wasm32-unknown-unknown", "thumbv6m-none-eabi" ] targets = [ "wasm32-unknown-unknown", "thumbv6m-none-eabi" ]