From 1a0301ddd9b14639da6adc5b1f9a0d6f9ed90cea Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:48:26 -0500 Subject: [PATCH] converted codebase to pico 2 --- southbridge/.cargo/config.toml | 5 ++- southbridge/Cargo.lock | 7 +++ southbridge/Cargo.toml | 4 +- southbridge/build.rs | 1 - southbridge/memory.x | 78 ++++++++++++++++++++++++++++++--- southbridge/rust-toolchain.toml | 10 ----- southbridge/src/main.rs | 14 +++++- 7 files changed, 98 insertions(+), 21 deletions(-) delete mode 100644 southbridge/rust-toolchain.toml diff --git a/southbridge/.cargo/config.toml b/southbridge/.cargo/config.toml index 6e392c3..27cdb53 100644 --- a/southbridge/.cargo/config.toml +++ b/southbridge/.cargo/config.toml @@ -1,5 +1,6 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "elf2uf2-rs --deploy --serial --verbose" +#runner = "elf2uf2-rs --deploy --serial --verbose" +runner = "picotool load -u -v -x -t elf" [build] -target = "thumbv6m-none-eabi" +target = "thumbv8m.main-none-eabihf" diff --git a/southbridge/Cargo.lock b/southbridge/Cargo.lock index 27b61cc..77cd154 100644 --- a/southbridge/Cargo.lock +++ b/southbridge/Cargo.lock @@ -404,6 +404,7 @@ dependencies = [ "pio", "pio-proc", "rand_core", + "rp-binary-info", "rp-pac", "rp2040-boot2", "sha2-const-stable", @@ -1212,6 +1213,12 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "rp-binary-info" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534e2a451671116f5b9391cb15fae43b9abdc56817bcaca9a95ed32c3e4c6b38" + [[package]] name = "rp-pac" version = "7.0.0" diff --git a/southbridge/Cargo.toml b/southbridge/Cargo.toml index 6a74c2b..3a0504e 100644 --- a/southbridge/Cargo.toml +++ b/southbridge/Cargo.toml @@ -13,11 +13,11 @@ embedded-storage = "0.3.1" cortex-m-rt = "0.7.3" -embassy-executor = { version = "0.7", features = ["task-arena-size-1024", "arch-cortex-m", "executor-thread", "executor-interrupt"] } +embassy-executor = { version = "0.7", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] } embassy-sync = { version = "0.6" } embassy-time = { version = "0.4" } cortex-m = { version = "0.7.6" } -embassy-rp = { version = "0.3", features = ["unstable-pac", "time-driver", "critical-section-impl", "rp2040"] } +embassy-rp = { version = "0.3", features = ["unstable-pac", "time-driver", "critical-section-impl", "rp235xa", "binary-info"] } embassy-usb-logger = "0.4.0" log = "0.4" diff --git a/southbridge/build.rs b/southbridge/build.rs index 1f25630..cd1a264 100644 --- a/southbridge/build.rs +++ b/southbridge/build.rs @@ -31,5 +31,4 @@ 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"); } diff --git a/southbridge/memory.x b/southbridge/memory.x index b88a8bd..c803896 100644 --- a/southbridge/memory.x +++ b/southbridge/memory.x @@ -1,7 +1,75 @@ -MEMORY -{ -BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 -FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 - RAM : ORIGIN = 0x20000000, LENGTH = 264K +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. + */ + SRAM4 : ORIGIN = 0x20080000, LENGTH = 4K + SRAM5 : 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); diff --git a/southbridge/rust-toolchain.toml b/southbridge/rust-toolchain.toml deleted file mode 100644 index f139e35..0000000 --- a/southbridge/rust-toolchain.toml +++ /dev/null @@ -1,10 +0,0 @@ -# Before upgrading check that everything is available on all tier1 targets here: -# https://rust-lang.github.io/rustup-components-history -[toolchain] -channel = "stable" -components = [ "rustfmt" ] -targets = [ - "thumbv6m-none-eabi", - "thumbv7em-none-eabihf", - "riscv32imac-unknown-none-elf", -] diff --git a/southbridge/src/main.rs b/southbridge/src/main.rs index ad0d1a1..a5000e5 100644 --- a/southbridge/src/main.rs +++ b/southbridge/src/main.rs @@ -5,7 +5,7 @@ use core::{panic::PanicInfo, sync::atomic::Ordering}; use common::{Command, Response, SensorData, BAUDRATE}; use embassy_executor::Spawner; -use embassy_rp::{bind_interrupts, peripherals::{UART0, UART1, USB}, pwm::{self, Pwm}, uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, BufferedUartTx, Config}, usb::Driver}; +use embassy_rp::{bind_interrupts, block::ImageDef, gpio::{Level, Output}, peripherals::{UART0, UART1, USB}, pwm::{self, Pwm}, uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, BufferedUartTx, Config}, usb::Driver}; use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel}; use embassy_time::{with_deadline, with_timeout, Duration, Instant, Timer}; use embedded_io::Write; @@ -25,6 +25,10 @@ bind_interrupts!(struct Irqs { pub static COMMANDS: Channel = Channel::new(); pub static SENSOR_DATA: Channel = Channel::new(); +#[link_section = ".start_block"] +#[used] +pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); + #[embassy_executor::task] async fn logger_task(driver: Driver<'static, USB>) { embassy_usb_logger::run!(1024, log::LevelFilter::Trace, driver); @@ -40,6 +44,10 @@ fn panic( info: &PanicInfo) -> ! { async fn main(spawner: Spawner) { let p = embassy_rp::init(Default::default()); + let mut led = Output::new(p.PIN_25, Level::Low); + + led.set_high(); + let driver = Driver::new(p.USB, Irqs); spawner.spawn(logger_task(driver)).unwrap(); @@ -74,6 +82,10 @@ async fn main(spawner: Spawner) { let mut enable_watchdog = Instant::now(); let enable_watchdog_time = Duration::from_millis(50); + Timer::after_secs(1).await; + info!("ready"); + Timer::after_secs(1).await; + loop { if !enabled.load(Ordering::Acquire) {