Use pico bsp (#10)

* Switch from a HAL to a BSP based project

* Add comments about alternative runner in .cargo/config
This commit is contained in:
9names 2021-12-05 15:56:06 +11:00 committed by GitHub
parent 34903fc263
commit f766fcb031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 10 deletions

View File

@ -1,5 +1,9 @@
# Choose a default "cargo run" tool.
# probe-run is recommended if you have a debugger
# elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] [target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-run --chip RP2040" runner = "probe-run --chip RP2040"
# runner = "elf2uf2-rs -d
rustflags = [ rustflags = [
"-C", "linker=flip-link", "-C", "linker=flip-link",

View File

@ -16,8 +16,17 @@ defmt = "0.3.0"
defmt-rtt = "0.3.0" defmt-rtt = "0.3.0"
panic-probe = { version = "0.3.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
rp2040-hal = { git = "https://github.com/rp-rs/rp-hal", branch="main", features=["rt"] } # We're using a Pico by default on this template
rp2040-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" } pico = { git = "https://github.com/rp-rs/rp-hal", branch="main"}
# but you can use any BSP. Uncomment this to use the pro_micro_rp2040 BSP instead
# pro_micro_rp2040 = { git = "https://github.com/rp-rs/rp-hal", branch="main"}
# If you're not going to use a Board Support Package you'll need these:
#rp2040-hal = { git = "https://github.com/rp-rs/rp-hal", branch="main", features=["rt"] }
#rp2040-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" }
# cargo build/run # cargo build/run
[profile.dev] [profile.dev]

View File

@ -4,6 +4,8 @@ MEMORY {
RAM : ORIGIN = 0x20000000, LENGTH = 256K RAM : ORIGIN = 0x20000000, LENGTH = 256K
} }
EXTERN(BOOT2_FIRMWARE)
SECTIONS { SECTIONS {
/* ### Boot loader */ /* ### Boot loader */
.boot2 ORIGIN(BOOT2) : .boot2 ORIGIN(BOOT2) :

View File

@ -10,19 +10,19 @@ use defmt_rtt as _;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint; use embedded_time::fixed_point::FixedPoint;
use panic_probe as _; use panic_probe as _;
use rp2040_hal as hal;
use hal::{ // Provide an alias for our BSP so we can switch targets quickly.
// Uncomment the BSP you included in Cargo.toml, the rest of the code does not need to change.
use pico as bsp;
// use pro_micro_rp2040 as bsp;
use bsp::hal::{
clocks::{init_clocks_and_plls, Clock}, clocks::{init_clocks_and_plls, Clock},
pac, pac,
sio::Sio, sio::Sio,
watchdog::Watchdog, watchdog::Watchdog,
}; };
#[link_section = ".boot2"]
#[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
info!("Program start"); info!("Program start");
@ -47,14 +47,14 @@ fn main() -> ! {
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
let pins = hal::gpio::Pins::new( let pins = bsp::Pins::new(
pac.IO_BANK0, pac.IO_BANK0,
pac.PADS_BANK0, pac.PADS_BANK0,
sio.gpio_bank0, sio.gpio_bank0,
&mut pac.RESETS, &mut pac.RESETS,
); );
let mut led_pin = pins.gpio25.into_push_pull_output(); let mut led_pin = pins.led.into_push_pull_output();
loop { loop {
info!("on!"); info!("on!");