From 467c4632c3afff7d7e222bda439b39fd1a8dbd7d Mon Sep 17 00:00:00 2001 From: RenovateBot Date: Sun, 5 Jan 2025 21:07:03 +0000 Subject: [PATCH 1/5] Update Rust crate embassy-executor to 0.7.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9c4f8fa..7e2d36e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -embassy-executor = { version = "0.5.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] } +embassy-executor = { version = "0.7.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] } embassy-rp = { version = "0.1.0", features = ["unstable-pac", "time-driver", "critical-section-impl"] } embassy-futures = { version = "0.1.1" } From 0014635cae78a942a3bcab064b217cfff8697700 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Wed, 12 Feb 2025 20:22:10 +0100 Subject: [PATCH 2/5] Update for rp2350 --- .cargo/config.toml | 6 +--- Cargo.toml | 17 ++++++++-- build.rs | 2 -- memory.x | 84 +++++++++++++++++++++++++++++++++++++++------- 4 files changed, 86 insertions(+), 23 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 7986e53..9fdfeab 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -9,8 +9,4 @@ runner = "elf2uf2-rs -d" [build] -# Cortex-M0 and Cortex-M0+ -target = "thumbv6m-none-eabi" - -[env] -# DEFMT_LOG = "debug" \ No newline at end of file +target = "thumbv8m.main-none-eabihf" diff --git a/Cargo.toml b/Cargo.toml index 7e2d36e..cd95380 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,19 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -embassy-executor = { version = "0.7.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] } -embassy-rp = { version = "0.1.0", features = ["unstable-pac", "time-driver", "critical-section-impl"] } +embassy-executor = { version = "0.7.0", features = [ + "task-arena-size-32768", + "arch-cortex-m", + "executor-thread", + "executor-interrupt", +] } +embassy-rp = { version = "0.3.1", features = [ + "unstable-pac", + "time-driver", + "critical-section-impl", + "rp235xa", +] } embassy-futures = { version = "0.1.1" } -cortex-m-rt = "0.7.4" +cortex-m-rt = "0.7.5" +cortex-m = { version = "0.7.7", features = ["inline-asm"] } diff --git a/build.rs b/build.rs index 113c72e..cd1a264 100644 --- a/build.rs +++ b/build.rs @@ -31,6 +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"); - // println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); } diff --git a/memory.x b/memory.x index 771b8fa..8b379f5 100644 --- a/memory.x +++ b/memory.x @@ -1,17 +1,75 @@ MEMORY { - BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 - FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 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 */ -} \ No newline at end of file +/* 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 From e26ef569e519cf7aadf167d23fd71855af9eccf6 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 13 Feb 2025 07:03:46 +0100 Subject: [PATCH 3/5] Add features for rp2040 and rp2350 --- .cargo/config.toml | 11 +++-------- .gitea/workflows/pull_request.yaml | 13 +++++++++++++ Cargo.toml | 6 ++++++ build.rs | 14 +++++++++++++- rp_2040_memory.x | 17 +++++++++++++++++ memory.x => rp_2350_memory.x | 0 rust-toolchain.toml | 5 +++-- src/main.rs | 11 +++++++++++ 8 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 rp_2040_memory.x rename memory.x => rp_2350_memory.x (100%) diff --git a/.cargo/config.toml b/.cargo/config.toml index 9fdfeab..f93369d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,12 +1,7 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# Choose a default "cargo run" tool: -# - probe-run provides flashing and defmt via a hardware debugger -# - cargo embed offers flashing, rtt, defmt and a gdb server via a hardware debugger -# it is configured via the Embed.toml in the root of this project -# - elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode -# runner = "probe-run --chip RP2040" -# runner = "cargo embed" -runner = "elf2uf2-rs -d" +runner = "picotool load -u -v -x -t elf" +# runner = "elf2uf2-rs -d" # rp2040 [build] target = "thumbv8m.main-none-eabihf" +# target = "thumbv6m-none-eabi" # rp2040 diff --git a/.gitea/workflows/pull_request.yaml b/.gitea/workflows/pull_request.yaml index 09e6ee8..d4e66b9 100644 --- a/.gitea/workflows/pull_request.yaml +++ b/.gitea/workflows/pull_request.yaml @@ -10,7 +10,20 @@ jobs: steps: - uses: https://github.com/actions/checkout@main + - uses: https://github.com/SebRollen/toml-action@v1.2.0 + id: read_rust_toolchain + with: + file: rust-toolchain + field: toolchain.targets + id: read_rust_components + with: + file: rust-toolchain + field: toolchain.components + - uses: https://github.com/dtolnay/rust-toolchain@stable + with: + toolchain: ${{ steps.read_rust_toolchain.outputs.value }} + components: ${{ steps.read_rust_components.outputs.value }} - name: Build run: cargo build \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index cd95380..40030b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,9 @@ embassy-futures = { version = "0.1.1" } cortex-m-rt = "0.7.5" cortex-m = { version = "0.7.7", features = ["inline-asm"] } + +[features] +rp2350 = ["embassy-rp/rp235xa"] +rp2040 = ["embassy-rp/rp2040"] + +default = ["rp2350"] diff --git a/build.rs b/build.rs index cd1a264..afb8f34 100644 --- a/build.rs +++ b/build.rs @@ -17,10 +17,19 @@ fn main() { // 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()); + + #[cfg(feature = "rp2040")] File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("memory.x")) + .write_all(include_bytes!("rp_2040_memory.x")) .unwrap(); + + #[cfg(feature = "rp2350")] + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("rp_2350_memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); // By default, Cargo will re-run a build script whenever @@ -31,4 +40,7 @@ fn main() { println!("cargo:rustc-link-arg-bins=--nmagic"); println!("cargo:rustc-link-arg-bins=-Tlink.x"); + + #[cfg(feature = "rp2040")] + println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); } diff --git a/rp_2040_memory.x b/rp_2040_memory.x new file mode 100644 index 0000000..771b8fa --- /dev/null +++ b/rp_2040_memory.x @@ -0,0 +1,17 @@ +MEMORY { + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + + /* Pick one of the two options for RAM layout */ + + /* 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 + + /* OPTION B: Keep the unstriped sections separate */ + /* RAM: ORIGIN = 0x20000000, LENGTH = 256K */ + /* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */ + /* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */ +} \ No newline at end of file diff --git a/memory.x b/rp_2350_memory.x similarity index 100% rename from memory.x rename to rp_2350_memory.x diff --git a/rust-toolchain.toml b/rust-toolchain.toml index dfac03c..2512127 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,4 @@ [toolchain] -components = [ "rust-src", "rustfmt", "llvm-tools" ] -targets = ["thumbv6m-none-eabi"] \ No newline at end of file +components = ["rust-src", "rustfmt", "llvm-tools"] +targets = ["thumbv8m.main-none-eabihf"] +# targets = ["thumbv6m-none-eabi"] diff --git a/src/main.rs b/src/main.rs index 87ed5d5..f5b7ef1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,12 @@ #![no_std] #![no_main] +#[cfg(not(all( + not(all(feature = "rp2040", feature = "rp2350")), + any(feature = "rp2040", feature = "rp2350") +)))] +compile_error!("Enable either feature rp2040 (pico 1) or feature rp2350 (pico 2)"); + use core::panic::PanicInfo; use embassy_executor::Spawner; @@ -11,6 +17,11 @@ fn panic(_info: &PanicInfo) -> ! { loop {} } +#[cfg(feature = "rp2350")] +#[link_section = ".start_block"] +#[used] +pub static IMAGE_DEF: embassy_rp::block::ImageDef = embassy_rp::block::ImageDef::secure_exe(); + #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_rp::init(Default::default()); From 0a760af4dcb14992c12545c5fecf2dd65404a929 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 13 Feb 2025 07:06:11 +0100 Subject: [PATCH 4/5] Improve action --- .../{pull_request.yaml => push_non_master.yaml} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename .gitea/workflows/{pull_request.yaml => push_non_master.yaml} (80%) diff --git a/.gitea/workflows/pull_request.yaml b/.gitea/workflows/push_non_master.yaml similarity index 80% rename from .gitea/workflows/pull_request.yaml rename to .gitea/workflows/push_non_master.yaml index d4e66b9..898b577 100644 --- a/.gitea/workflows/pull_request.yaml +++ b/.gitea/workflows/push_non_master.yaml @@ -1,9 +1,10 @@ -name: Merge Build -run_name: Test successful build on merge request +name: Build on feature branch +run_name: Test successful build on push on: - pull_request: - types: [opened, reopened, edited, review_requested, synchronize] + push: + branches-ignore: + - master jobs: Build: From 434599c09ee7505d5aef4dca99fba74e4b080935 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 13 Feb 2025 07:07:06 +0100 Subject: [PATCH 5/5] Add basic script for master --- .gitea/workflows/push_master.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .gitea/workflows/push_master.yaml diff --git a/.gitea/workflows/push_master.yaml b/.gitea/workflows/push_master.yaml new file mode 100644 index 0000000..69b3951 --- /dev/null +++ b/.gitea/workflows/push_master.yaml @@ -0,0 +1,30 @@ +name: Build on master branch +run_name: Test successful build on push + +on: + push: + branches: + - master + +jobs: + Build: + steps: + - uses: https://github.com/actions/checkout@main + + - uses: https://github.com/SebRollen/toml-action@v1.2.0 + id: read_rust_toolchain + with: + file: rust-toolchain + field: toolchain.targets + id: read_rust_components + with: + file: rust-toolchain + field: toolchain.components + + - uses: https://github.com/dtolnay/rust-toolchain@stable + with: + toolchain: ${{ steps.read_rust_toolchain.outputs.value }} + components: ${{ steps.read_rust_components.outputs.value }} + + - name: Build + run: cargo build \ No newline at end of file