diff --git a/.cargo/config.toml b/.cargo/config.toml index 05f45c9..fb8d408 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,7 +3,7 @@ runner = "probe-rs run --chip RP2040" [build] -target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ +target = ["thumbv6m-none-eabi", "thumbv8m.main-none-eabihf"] [env] DEFMT_LOG = "info" diff --git a/Cargo.lock b/Cargo.lock index 7790c45..19faa63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -542,6 +542,7 @@ dependencies = [ "pio", "rand_core 0.6.4", "rand_core 0.9.3", + "rp-binary-info", "rp-pac", "rp2040-boot2", "sha2-const-stable", @@ -1405,6 +1406,12 @@ dependencies = [ "svgbobdoc", ] +[[package]] +name = "rp-binary-info" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ed2051a0bf2c726df01cfce378ed8a367be2a6e402fc183857f429a346d429" + [[package]] name = "rp-pac" version = "7.0.0" diff --git a/Cargo.toml b/Cargo.toml index 415ee26..34ff267 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,11 +27,14 @@ embassy-executor = { version = "*", features = [ embassy-rp = { version = "*", features = [ "unstable-pac", "rp2040", + # "rp235xa", "time-driver", "critical-section-impl", - "defmt" + "defmt", + "binary-info", + "unstable-pac" ] } -embassy-time = { version = "*", features = ["defmt"] } +embassy-time = { version = "*", features = ["defmt", "defmt-timestamp-uptime"] } # embassy-usb-logger = { version = "*" } embassy-net = { version = "*", features = [ "proto-ipv4", @@ -42,7 +45,7 @@ embassy-net = { version = "*", features = [ ] } embassy-sync = { version = "*", features = ["defmt"] } cyw43-pio = { version = "*", features = ["defmt"] } -cyw43 = { version = "*", features = ["defmt"] } +cyw43 = { version = "*", features = ["defmt", "firmware-logs"] } defmt = "1.0.1" defmt-rtt = "1.0.0" @@ -71,4 +74,7 @@ sha1 = { version = "*", default-features = false } base64 = { version = "*", default-features = false } anyhow = { version = "*", default-features = false } -embedded-alloc = "*" \ No newline at end of file +embedded-alloc = "*" + +# [target.thumbv8m.main-none-eabihf.dependencies] +# embassy-rp = { features = "rp235xa" } \ No newline at end of file diff --git a/build.rs b/build.rs index 3f915f9..1eb51eb 100644 --- a/build.rs +++ b/build.rs @@ -13,13 +13,27 @@ use std::fs::File; use std::io::Write; use std::path::PathBuf; +enum Target { + Pico, + Pico2, +} + fn main() { + let target = match env::var("TARGET").unwrap().as_str() { + "thumbv6m-none-eabi" => Target::Pico, + "thumbv8m.main-none-eabihf" => Target::Pico2, + t => panic!("Unsupported target : {}", t), + }; + // 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()); File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("memory.x")) + .write_all(match target { + Target::Pico => include_bytes!("memory_rp2040.x"), + Target::Pico2 => include_bytes!("memory_rp235x.x"), + }) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); @@ -31,6 +45,8 @@ fn main() { println!("cargo:rustc-link-arg-bins=--nmagic"); println!("cargo:rustc-link-arg-bins=-Tlink.x"); - println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); + if let Target::Pico = target { + println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); + } println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); } diff --git a/memory.x b/memory_rp2040.x similarity index 100% rename from memory.x rename to memory_rp2040.x diff --git a/memory_rp235x.x b/memory_rp235x.x new file mode 100644 index 0000000..0ed2a2b --- /dev/null +++ b/memory_rp235x.x @@ -0,0 +1,75 @@ +MEMORY { + /* + * The RP2350 has either external or internal flash. + * + * 2 MiB is a safe default here, although a Pico 2 has 4 MiB. + */ + FLASH : ORIGIN = 0x10000000, LENGTH = 2048K + /* + * RAM consists of 8 banks, SRAM0-SRAM7, with a striped mapping. + * This is usually good for performance, as it distributes load on + * those banks evenly. + */ + RAM : ORIGIN = 0x20000000, LENGTH = 512K + /* + * RAM banks 8 and 9 use a direct mapping. They can be used to have + * memory areas dedicated for some specific job, improving predictability + * of access times. + * Example: Separate stacks for core0 and core1. + */ + SRAM8 : ORIGIN = 0x20080000, LENGTH = 4K + SRAM9 : ORIGIN = 0x20081000, LENGTH = 4K +} + +SECTIONS { + /* ### Boot ROM info + * + * Goes after .vector_table, to keep it in the first 4K of flash + * where the Boot ROM (and picotool) can find it + */ + .start_block : ALIGN(4) + { + __start_block_addr = .; + KEEP(*(.start_block)); + KEEP(*(.boot_info)); + } > FLASH + +} INSERT AFTER .vector_table; + +/* move .text to start /after/ the boot info */ +_stext = ADDR(.start_block) + SIZEOF(.start_block); + +SECTIONS { + /* ### Picotool 'Binary Info' Entries + * + * Picotool looks through this block (as we have pointers to it in our + * header) to find interesting information. + */ + .bi_entries : ALIGN(4) + { + /* We put this in the header */ + __bi_entries_start = .; + /* Here are the entries */ + KEEP(*(.bi_entries)); + /* Keep this block a nice round size */ + . = ALIGN(4); + /* We put this in the header */ + __bi_entries_end = .; + } > FLASH +} INSERT AFTER .text; + +SECTIONS { + /* ### Boot ROM extra info + * + * Goes after everything in our program, so it can contain a signature. + */ + .end_block : ALIGN(4) + { + __end_block_addr = .; + KEEP(*(.end_block)); + } > FLASH + +} INSERT AFTER .uninit; + +PROVIDE(start_to_end = __end_block_addr - __start_block_addr); +PROVIDE(end_to_start = __start_block_addr - __end_block_addr); \ No newline at end of file diff --git a/pico-website-pico2.uf2 b/pico-website-pico2.uf2 new file mode 100644 index 0000000..398183f Binary files /dev/null and b/pico-website-pico2.uf2 differ