Last active
December 8, 2024 14:16
-
-
Save chmanie/a52c386ed77adbad4744b52abd13a52b to your computer and use it in GitHub Desktop.
Embassy RP2040 vs RP2350
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/.cargo/config.toml b/.cargo/config.toml | |
index a87e324..51c8973 100644 | |
--- a/.cargo/config.toml | |
+++ b/.cargo/config.toml | |
@@ -1,8 +1,10 @@ | |
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | |
-runner = "probe-rs run --chip RP2040" | |
+#runner = "probe-rs run --chip RP2040" | |
+#runner = "elf2uf2-rs -d" | |
+runner = "picotool load -u -v -x -t elf" | |
[build] | |
-target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ | |
+target = "thumbv8m.main-none-eabihf" | |
[env] | |
DEFMT_LOG = "debug" | |
diff --git a/Cargo.toml b/Cargo.toml | |
index 4fac4c3..5efdb6f 100644 | |
--- a/Cargo.toml | |
+++ b/Cargo.toml | |
@@ -28,7 +28,7 @@ embassy-rp = { version = "0.2", features = [ | |
"unstable-pac", | |
"time-driver", | |
"critical-section-impl", | |
- "rp2040", | |
+ "rp235xb", | |
"binary-info", | |
] } | |
embassy-futures = { version = "0.1" } | |
diff --git a/build.rs b/build.rs | |
index 3f915f9..30691aa 100644 | |
--- a/build.rs | |
+++ b/build.rs | |
@@ -31,6 +31,5 @@ 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"); | |
println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | |
} | |
diff --git a/memory.x b/memory.x | |
index 853faae..c803896 100644 | |
--- a/memory.x | |
+++ b/memory.x | |
@@ -1,17 +1,75 @@ | |
MEMORY { | |
- BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 | |
- FLASH : ORIGIN = 0x10000100, LENGTH = 16384K - 0x100 | |
+ /* | |
+ * 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 | |
+} | |
- /* Pick one of the two options for RAM layout */ | |
+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 | |
- /* OPTION A: Use all RAM banks as one big block */ | |
- /* Reasonable, unless you are doing something */ | |
- /* really particular with DMA or other concurrent */ | |
- /* access that would benefit from striping */ | |
- RAM : ORIGIN = 0x20000000, LENGTH = 264K | |
+} INSERT AFTER .vector_table; | |
- /* OPTION B: Keep the unstriped sections separate */ | |
- /* RAM: ORIGIN = 0x20000000, LENGTH = 256K */ | |
- /* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */ | |
- /* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */ | |
-} | |
+/* 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/src/main.rs b/src/main.rs | |
index 882cb50..62ab9af 100644 | |
--- a/src/main.rs | |
+++ b/src/main.rs | |
@@ -15,6 +15,7 @@ use defmt::info; | |
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice; | |
use embassy_executor::{Executor, Spawner}; | |
use embassy_futures::select::select; | |
+use embassy_rp::block::ImageDef; | |
use embassy_rp::multicore::{spawn_core1, Stack}; | |
use embassy_rp::peripherals::{UART0, UART1, USB}; | |
use embassy_rp::spi::{self, Phase, Polarity, Spi}; | |
@@ -43,6 +44,23 @@ use sequential_storage::{ | |
map::{fetch_item, store_item}, | |
}; | |
+#[link_section = ".start_block"] | |
+#[used] | |
+pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); | |
+ | |
bind_interrupts!(struct Irqs { | |
I2C1_IRQ => i2c::InterruptHandler<I2C1>; | |
PIO0_IRQ_0 => pio::InterruptHandler<PIO0>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment