Skip to content

Commit 6f29b7d

Browse files
committed
feat: translate the rp2040 project template for the rp235x
1 parent 920d2cc commit 6f29b7d

File tree

16 files changed

+340
-172
lines changed

16 files changed

+340
-172
lines changed

.cargo/config.toml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
1+
[target.thumbv8m.main-none-eabihf]
22
# Choose a default "cargo run" tool (see README for more info)
33
# - `probe-rs` provides flashing and defmt via a hardware debugger, and stack unwind on panic
4-
# - elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
5-
runner = "probe-rs run --chip RP2040 --protocol swd"
6-
# runner = "elf2uf2-rs -d"
4+
# - `picotool` loads an elf, skipping unchanged flash sectors, verify it, and execute it
5+
#runner = "probe-rs run --chip RP235x --protocol swd"
6+
runner = "picotool load -u -v -x -t elf"
77

8-
linker = "flip-link"
8+
# Pass some extra options to rustc, some of which get passed on to the linker.
9+
#
10+
# * linker argument --nmagic turns off page alignment of sections (which saves
11+
# flash space)
12+
# * linker argument -Tlink.x tells the linker to use link.x as a linker script.
13+
# This is usually provided by the cortex-m-rt crate, and by default the
14+
# version in that crate will include a file called `memory.x` which describes
15+
# the particular memory layout for your specific chip.
16+
# * linker argument -Tdefmt.x also tells the linker to use `defmt.x` as a
17+
# secondary linker script. This is required to make defmt_rtt work.
918
rustflags = [
10-
"-C", "link-arg=--nmagic",
11-
"-C", "link-arg=-Tlink.x",
12-
"-C", "link-arg=-Tdefmt.x",
13-
14-
# Code-size optimizations.
15-
# trap unreachable can save a lot of space, but requires nightly compiler.
16-
# uncomment the next line if you wish to enable it
17-
# "-Z", "trap-unreachable=no",
18-
"-C", "no-vectorize-loops",
19+
"-C", "link-arg=--nmagic",
20+
"-C", "link-arg=-Tlink.x",
21+
"-C", "link-arg=-Tdefmt.x",
22+
"-C", "target-cpu=cortex-m33",
1923
]
2024

2125
[build]
22-
target = "thumbv6m-none-eabi"
26+
target = "thumbv8m.main-none-eabihf"
2327

2428
[env]
2529
DEFMT_LOG = "debug"

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.vscode/launch.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"preLaunchTask": "rust: cargo build",
77
"type": "probe-rs-debug",
88
"request": "launch",
9-
"name": "rp2040-project",
9+
"name": "rp235x-project",
1010
"cwd": "${workspaceFolder}",
11-
"chip": "rp2040",
12-
// RP2040 doesn't support connectUnderReset
11+
"chip": "rp235x",
12+
// TODO: Does RP235x support connectUnderReset?
1313
"connectUnderReset": false,
1414
"speed": 4000,
1515
"runtimeExecutable": "probe-rs",
@@ -23,16 +23,16 @@
2323
"coreConfigs": [
2424
{
2525
"coreIndex": 0,
26-
"programBinary": "target/thumbv6m-none-eabi/debug/rp2040-project-template",
26+
"programBinary": "target/thumbv8m.main-none-eabihf/debug/rp235x-project-template",
2727
"rttEnabled": true
2828
// Uncomment this if you've downloaded the SVD from
29-
// https://github.com/raspberrypi/pico-sdk/raw/1.3.1/src/rp2040/hardware_regs/rp2040.svd
29+
// https://github.com/raspberrypi/pico-sdk/raw/2.1.1/src/rp2350/hardware_regs/RP2350.svd
3030
// and placed it in the .vscode directory
31-
// "svdFile": "./.vscode/rp2040.svd",
31+
// "svdFile": "./.vscode/rp235x.svd",
3232
}
3333
],
3434
"consoleLogLevel": "Info", //Error, Warn, Info, Debug, Trace
3535
"wireProtocol": "Swd"
3636
}
3737
]
38-
}
38+
}

Cargo.toml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
edition = "2021"
3-
name = "rp2040-project-template"
3+
name = "rp235x-project-template"
44
version = "0.1.0"
55
license = "MIT OR Apache-2.0"
66

@@ -13,64 +13,50 @@ defmt = "1"
1313
defmt-rtt = "1"
1414
panic-probe = { version = "1", features = ["print-defmt"] }
1515

16-
# We're using a Pico by default on this template
17-
rp-pico = "0.9"
18-
19-
# but you can use any BSP. Uncomment this to use the pro_micro_rp2040 BSP instead
20-
# sparkfun-pro-micro-rp2040 = "0.8"
16+
# We're using a Pico 2 by default on this template
17+
#rp-pico2 = "0.9" # TODO: Do we have that crate already ?
2118

2219
# If you're not going to use a Board Support Package you'll need these:
23-
# rp2040-hal = { version="0.11", features=["rt", "critical-section-impl"] }
24-
# rp2040-boot2 = "0.3"
20+
rp235x-hal = { version="0.3", features=["rt", "critical-section-impl"] }
2521

2622
# cargo build/run
2723
[profile.dev]
28-
codegen-units = 1
2924
debug = 2
3025
debug-assertions = true
31-
incremental = false
32-
opt-level = 3
26+
opt-level = 2
3327
overflow-checks = true
3428

3529
# cargo build/run --release
3630
[profile.release]
37-
codegen-units = 1
3831
debug = 2
3932
debug-assertions = false
40-
incremental = false
4133
lto = 'fat'
42-
opt-level = 3
34+
opt-level = 2
4335
overflow-checks = false
4436

4537
# do not optimize proc-macro crates = faster builds from scratch
4638
[profile.dev.build-override]
47-
codegen-units = 8
4839
debug = false
4940
debug-assertions = false
50-
opt-level = 0
5141
overflow-checks = false
42+
opt-level = 0
5243

5344
[profile.release.build-override]
54-
codegen-units = 8
5545
debug = false
5646
debug-assertions = false
57-
opt-level = 0
5847
overflow-checks = false
48+
opt-level = 0
5949

6050
# cargo test
6151
[profile.test]
62-
codegen-units = 1
6352
debug = 2
6453
debug-assertions = true
65-
incremental = false
66-
opt-level = 3
54+
opt-level = 2
6755
overflow-checks = true
6856

6957
# cargo test --release
7058
[profile.bench]
71-
codegen-units = 1
7259
debug = 2
7360
debug-assertions = false
74-
incremental = false
7561
lto = 'fat'
7662
opt-level = 3

README.md

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Project template for rp2040-hal
1+
# Project template for rp235x-hal
22

3-
This template is intended as a starting point for developing your own firmware based on the rp2040-hal.
3+
This template is intended as a starting point for developing your own firmware based on the rp235x-hal.
44

55
It includes all of the `knurling-rs` tooling as showcased in https://github.com/knurling-rs/app-template (`defmt`, `defmt-rtt`, `panic-probe`, `flip-link`) to make development as easy as possible.
66

@@ -21,7 +21,6 @@ If you aren't using a debugger (or want to use other debugging configurations),
2121
<li><a href="#project-creation">Project Creation</a></li>
2222
<li><a href="#running">Running</a></li>
2323
<li><a href="#alternative-runners">Alternative runners</a></li>
24-
<li><a href="#notes-on-using-rp2040_boot2">Notes on using rp2040_boot2</a></li>
2524
<li><a href="#feature-flags">Feature flags</a></li>
2625
<li><a href="#roadmap">Roadmap</a></li>
2726
<li><a href="#contributing">Contributing</a></li>
@@ -37,7 +36,7 @@ If you aren't using a debugger (or want to use other debugging configurations),
3736

3837
- The standard Rust tooling (cargo, rustup) which you can install from https://rustup.rs/
3938

40-
- Toolchain support for the cortex-m0+ processors in the rp2040 (thumbv6m-none-eabi)
39+
- Toolchain support for the cortex-m33 processors in the rp235x (thumbv8m.main-none-eabihf)
4140

4241
- flip-link - this allows you to detect stack-overflows on the first core, which is the only supported target for now.
4342

@@ -55,13 +54,13 @@ If you aren't using a debugger (or want to use other debugging configurations),
5554
<details open="open">
5655
<summary><h2 style="display: inline-block" id="installation-of-development-dependencies">Installation of development dependencies</h2></summary>
5756

57+
If you are using Nix, you can use the `devShell` made available in `flake.nix`. Otherwise, you can follow these commands (provided you already have [`Rustup`](https://rustup.rs/) installed):
58+
5859
```sh
59-
rustup target install thumbv6m-none-eabi
60+
rustup target install thumbv8m.main-none-eabihf
6061
cargo install flip-link
6162
# Installs the probe-rs tools, including probe-rs run, our recommended default runner
6263
cargo install --locked probe-rs-tools
63-
# If you want to use elf2uf2-rs instead, do...
64-
cargo install --locked elf2uf2-rs
6564
```
6665
If you get the error ``binary `cargo-embed` already exists`` during installation of probe-rs, run `cargo uninstall cargo-embed` to uninstall your older version of cargo-embed before trying again.
6766

@@ -74,7 +73,7 @@ If you get the error ``binary `cargo-embed` already exists`` during installation
7473
### Using `cargo-generate`
7574

7675
```sh
77-
cargo generate --git https://github.com/rp-rs/rp2040-project-template
76+
cargo generate --git https://github.com/rp-rs/rp235x-project-template
7877
```
7978

8079
Follow the wizard 🪄 and enjoy your new project.
@@ -192,30 +191,25 @@ Some of the options for your `runner` are listed below:
192191
*Step 5* - Launch a debug session by choosing `Run`>`Start Debugging` (or press F5)
193192

194193
* **Loading a UF2 over USB**
195-
*Step 1* - Install [`elf2uf2-rs`](https://github.com/JoNil/elf2uf2-rs):
196-
197-
```console
198-
$ cargo install elf2uf2-rs --locked
199-
```
194+
*Step 1* - Install [`picotool`](https://github.com/raspberrypi/picotool):
200195

201196
*Step 2* - Modify `.cargo/config` to change the default runner
202197

203198
```toml
204199
[target.`cfg(all(target-arch = "arm", target_os = "none"))`]
205-
runner = "elf2uf2-rs -d"
200+
runner = "picotool load -u -v -x -t elf"
206201
```
207202

208203
The all-Arm wildcard `'cfg(all(target_arch = "arm", target_os = "none"))'` is used
209204
by default in the template files, but may also be replaced by
210-
`thumbv6m-none-eabi`.
205+
`thumbv8m.main-none-eabihf`.
211206

212-
*Step 3* - Boot your RP2040 into "USB Bootloader mode", typically by rebooting
207+
*Step 3* - Boot your RP235x into "USB Bootloader mode", typically by rebooting
213208
whilst holding some kind of "Boot Select" button. On Linux, you will also need
214209
to 'mount' the device, like you would a USB Thumb Drive.
215210

216211
*Step 4* - Use `cargo run`, which will compile the code and start the
217-
specified 'runner'. As the 'runner' is the `elf2uf2-rs` tool, it will build a UF2
218-
file and copy it to your RP2040.
212+
specified 'runner'. As the 'runner' is the `picotool`, it will copy the firmware to your RP235x.
219213

220214
```console
221215
$ cargo run --release
@@ -236,33 +230,17 @@ Some of the options for your `runner` are listed below:
236230
information in the ELF file in a way that `picotool info` can read it out, are
237231
not supported in Rust. An alternative is TBC.
238232

239-
</details>
240-
<!-- Notes on using rp2040_hal and rp2040_boot2 -->
241-
<details open="open">
242-
<summary><h2 style="display: inline-block" id="notes-on-using-rp2040_boot2">Notes on using rp2040_boot2</h2></summary>
243-
244-
The second-stage boot loader must be written to the .boot2 section. That
245-
is usually handled by the board support package (e.g.`rp-pico`). If you don't use
246-
one, you should initialize the boot loader manually. This can be done by adding the
247-
following to the beginning of main.rs:
248-
```rust
249-
use rp2040_boot2;
250-
#[link_section = ".boot2"]
251-
#[used]
252-
pub static BOOT_LOADER: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
253-
```
254-
255233
</details>
256234

257235
<!-- Feature flags -->
258236
<details open="open">
259237
<summary><h2 style="display: inline-block" id="feature-flags">Feature flags</h2></summary>
260238

261-
There are several [feature flags in rp2040-hal](https://docs.rs/rp2040-hal/latest/rp2040_hal/#crate-features).
262-
If you want to enable some of them, uncomment the `rp2040-hal` dependency in `Cargo.toml` and add the
239+
There are several [feature flags in rp235x-hal](https://docs.rs/rp235x-hal/latest/rp235x_hal/#crate-features).
240+
If you want to enable some of them, uncomment the `rp235x-hal` dependency in `Cargo.toml` and add the
263241
desired feature flags there. For example, to enable ROM functions for f64 math using the feature `rom-v2-intrinsics`:
264242
```
265-
rp2040-hal = { version="0.10", features=["rt", "critical-section-impl", "rom-v2-intrinsics"] }
243+
rp235x-hal = { version="0.3", features=["rt", "critical-section-impl", "rom-v2-intrinsics"] }
266244
```
267245
</details>
268246

@@ -273,7 +251,7 @@ Some of the options for your `runner` are listed below:
273251
NOTE These packages are under active development. As such, it is likely to
274252
remain volatile until a 1.0.0 release.
275253

276-
See the [open issues](https://github.com/rp-rs/rp2040-project-template/issues) for a list of
254+
See the [open issues](https://github.com/rp-rs/rp235x-project-template/issues) for a list of
277255
proposed features (and known issues).
278256

279257
## Contributing
@@ -287,7 +265,7 @@ The steps are:
287265
3. Make some changes to the code or documentation.
288266
4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
289267
5. Push to the Feature Branch (`git push origin feature/AmazingFeature`)
290-
6. Create a [New Pull Request](https://github.com/rp-rs/rp2040-project-template/pulls)
268+
6. Create a [New Pull Request](https://github.com/rp-rs/rp235x-project-template/pulls)
291269
7. An admin will review the Pull Request and discuss any changes that may be required.
292270
8. Once everyone is happy, the Pull Request can be merged by an admin, and your work is part of our project!
293271

@@ -311,5 +289,5 @@ under these terms.
311289

312290
## Contact
313291

314-
Raise an issue: [https://github.com/rp-rs/rp2040-project-template/issues](https://github.com/rp-rs/rp2040-project-template/issues)
292+
Raise an issue: [https://github.com/rp-rs/rp235x-project-template/issues](https://github.com/rp-rs/rp235x-project-template/issues)
315293
Chat to us on Matrix: [#rp-rs:matrix.org](https://matrix.to/#/#rp-rs:matrix.org)

build.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@
88
//! updating `memory.x` ensures a rebuild of the application with the
99
//! new memory settings.
1010
11-
use std::env;
1211
use std::fs::File;
1312
use std::io::Write;
1413
use std::path::PathBuf;
1514

1615
fn main() {
17-
// Put `memory.x` in our output directory and ensure it's
18-
// on the linker search path.
19-
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20-
File::create(out.join("memory.x"))
21-
.unwrap()
22-
.write_all(include_bytes!("memory.x"))
23-
.unwrap();
16+
// Put the linker script somewhere the linker can find it
17+
let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
2418
println!("cargo:rustc-link-search={}", out.display());
2519

26-
// By default, Cargo will re-run a build script whenever
27-
// any file in the project changes. By specifying `memory.x`
28-
// here, we ensure the build script is only re-run when
29-
// `memory.x` is changed.
20+
// The file `memory.x` is loaded by cortex-m-rt's `link.x` script, which
21+
// is what we specify in `.cargo/config.toml` for Arm builds
22+
let memory_x = include_bytes!("memory.x");
23+
let mut f = File::create(out.join("memory.x")).unwrap();
24+
f.write_all(memory_x).unwrap();
3025
println!("cargo:rerun-if-changed=memory.x");
26+
27+
println!("cargo:rerun-if-changed=build.rs");
3128
}

cargo-generate.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ pre = ["cargo-generate/remove_rprs.rhai"]
77
[placeholders]
88
flash_method = { prompt = "Which flashing method do you intend to use?", choices = [
99
"probe-rs",
10-
"elf2uf2-rs",
10+
"picotool",
1111
"custom",
1212
"none"
13-
], default = "probe-rs", type = "string" }
13+
], default = "picotool", type = "string" }
1414

1515
[conditional.'flash_method == "custom"'.placeholders]
1616
flash_method_custom = { prompt = "Enter the runner command to use", type = "string" }

0 commit comments

Comments
 (0)