From 0689e52da0c1cb82d865a1a9be7687935cddaa67 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 9 Aug 2025 21:24:00 +0200 Subject: [PATCH] Updated building dep --- rp2040_42/Cargo.toml | 4 +-- rp2040_42/build.rs | 14 ++++++++++ rp2040_42/memory.x | 63 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 rp2040_42/build.rs diff --git a/rp2040_42/Cargo.toml b/rp2040_42/Cargo.toml index 12d9413..f43b04c 100644 --- a/rp2040_42/Cargo.toml +++ b/rp2040_42/Cargo.toml @@ -24,11 +24,11 @@ hd44780-driver = "0.4.0" nb = "1.0" panic-halt = "0.2.0" panic-probe = {version = "0.3.1", features = ["print-defmt"]} -pio = "0.2.0" -pio-proc = "0.2.0" +pio = "0.3.0" portable-atomic = {version = "1.7.0", features = ["critical-section"]} rp2040-boot2 = "0.3.0" rp2040-hal = {version = "0.11.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"]} +rp-binary-info = {git = "https://github.com/rp-rs/rp-hal/", version ="0.1.2"} static_cell = "2.1.0" # USB hid dependencies diff --git a/rp2040_42/build.rs b/rp2040_42/build.rs new file mode 100644 index 0000000..b2dd9ec --- /dev/null +++ b/rp2040_42/build.rs @@ -0,0 +1,14 @@ +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put the linker script somewhere the linker can find it + let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); + let memory_x = include_bytes!("memory.x"); + let mut f = File::create(out.join("memory.x")).unwrap(); + f.write_all(memory_x).unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/rp2040_42/memory.x b/rp2040_42/memory.x index 4077aab..3377f6a 100644 --- a/rp2040_42/memory.x +++ b/rp2040_42/memory.x @@ -1,15 +1,72 @@ MEMORY { BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + /* + * Here we assume you have 2048 KiB of Flash. This is what the Pi Pico + * has, but your board may have more or less Flash and you should adjust + * this value to suit. + */ FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 - RAM : ORIGIN = 0x20000000, LENGTH = 256K + /* + * RAM consists of 4 banks, SRAM0-SRAM3, with a striped mapping. + * This is usually good for performance, as it distributes load on + * those banks evenly. + */ + RAM : ORIGIN = 0x20000000, LENGTH = 256K } EXTERN(BOOT2_FIRMWARE) - SECTIONS { - /* ### Boot loader */ + /* ### Boot loader + * + * An executable block of code which sets up the QSPI interface for + * 'Execute-In-Place' (or XIP) mode. Also sends chip-specific commands to + * the external flash chip. + * + * Must go at the start of external flash, where the Boot ROM expects it. + */ .boot2 ORIGIN(BOOT2) : { KEEP(*(.boot2)); } > BOOT2 } INSERT BEFORE .text; + +SECTIONS { + /* ### Boot ROM info + * + * Goes after .vector_table, to keep it in the first 512 bytes of flash, + * where picotool can find it + */ + .boot_info : ALIGN(4) + { + KEEP(*(.boot_info)); + } > FLASH + +} INSERT AFTER .vector_table; + +/* move .text to start /after/ the boot info */ +_stext = ADDR(.boot_info) + SIZEOF(.boot_info); + +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 { + .flash_end : { + __flash_binary_end = .; + } > FLASH +} INSERT AFTER .uninit;