Skip to content

Commit f6231e3

Browse files
authored
Merge pull request #1 from Systemscape/add-content
Add first chapter
2 parents 6a31586 + cdd3511 commit f6231e3

18 files changed

+157
-22
lines changed

src/SUMMARY.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
# Summary
22

3-
- [Getting Started With Embedded Rust 📟🦀](./index.md)
4-
- [Introduction](./introduction.md)
5-
- [Setup](./setup.md)
6-
3+
[Getting Started With Embedded Rust 🦀](./index.md)
4+
- [Introduction](./introduction/introduction.md)
5+
- [Who should use this Guide?](./introduction/who_should_use_this_guide.md)
6+
- [What you'll need (Prerequisites)](./introduction/what_youll_need_prerequisites.md)
7+
- [How to Use This Guide](./introduction/how_to_use_this_guide.md)
8+
- [Flashing Rust is Easier Than Brewing Coffee. ☕](./flashing/flashing_rust_is_easier_than_brewing_coffee.md)
9+
- [Setting Up Your Rust Embedded Toolchain](./flashing/setting-up-your-rust-embedded-toolchain.md)
10+
- [RP2350 MCU Flashing Methods](./flashing/rp2350_mcu_flashing_methods.md)
11+
- [Install tools for flashing](./flashing/install_tools_for_flashing.md)
12+
- [Starting a New Project – Blinky (RP2350 Template)](./flashing/starting_a_new_project_blinky_rp2350_template.md)
713
---
814

9-
# Exercises
10-
11-
- [First Exercise](./exercise1.md)
12-
- [Second Exercise](./exercise2.md)
13-
14-
---
15-
16-
# Final Words
17-
18-
- [Wrap-up](./wrapup.md)
19-

src/chapter_1.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/exercise1.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/exercise2.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Flashing Rust is Easier Than Brewing Coffee. ☕
2+
3+
Our first goal is to show that getting Rust code running on a real microcontroller is **surprisingly simple** – often just a few commands. We’ll set up the toolchain for the RP2350, compile a “blinky” program, and flash it to the board. By the end of this chapter, you’ll have an LED blinking on actual hardware, and you’ll see that putting Rust on a microchip is _literally easier than making a cup of coffee._
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Install tools for flashing
2+
3+
## Method 1: RP2350-built-in bootloader via drag & drop
4+
5+
As described in the previous chapter, you don't need to install any tools to flash the RP2350 using the RP2350-built-in bootloader if you use our online conversion method at <a href="https://elf2uf2.yrust.de/" target="_blank">elf2uf2.yrust.de</a>. If you prefer to convert it locally though, you will need to install `picotool`, as described in the next paragraph.
6+
7+
## Method 2: RP2350-built-in bootloader with picotool
8+
9+
The RP2040 and RP2350 have a built-in bootloader that presents the device as a USB drive when you plug it in with the BOOTSEL button pressed. You can copy a `.uf2` file to that drive to flash new firmware . For this, it’s helpful to install [picotool](https://github.com/raspberrypi/picotool/), a utility from Raspberry Pi that can convert binaries to UF2 and upload them. You can download a pre-built picotool binary from the [releases page](https://github.com/raspberrypi/picotool/releases) for your OS or build it from source.
10+
Their docs state that _You cannot just copy the binary into your PATH, else the Pico SDK will not be able to locate it._, however, if you only want to use the RP2350 with Rust code and don't plan on using the SDK, you absolutely can just copy the picotool binary to your PATH.
11+
12+
With picotool installed, you can now flash the RP2350 (given that the bootsel button is pressed when plugging it in) using:
13+
```bash
14+
picotool load -u -v -x -t elf your_file.elf
15+
```
16+
you can also convert `.elf` files to `.uf2` files using:
17+
```bash
18+
picotool uf2 convert your_file.elf your_file.uf2
19+
```
20+
21+
## Method 3: Probe-based flashing (SWD)
22+
Using an external debug probe or a second Pico as a probe, you can flash and debug the chip directly via the SWD interface. For this, we use **probe-rs**, a Rust project that replaces OpenOCD/GDB. We recommend installing using the [recommended install scripts](https://probe.rs/docs/getting-started/installation/), which provides the probe-rs CLI and associated tools:
23+
```bash
24+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-tools-installer.sh | sh
25+
```
26+
This gives you commands like probe-rs flash and also includes probe-run (for running programs with semi-hosted debugging). _(If you’re curious: probe-rs is a pure-Rust implementation of the ARM debugging protocol and works with CMSIS-DAP, J-Link, etc. It makes flashing and even debuggingfirmware straightforward.)_
27+
28+
## (optional) Install cargo-generate
29+
We will use cargo-generate to quickly bootstrap projects from templates. Install it with:
30+
```bash
31+
cargo install cargo-generate
32+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# RP2350 MCU Flashing Methods
2+
3+
There are three main ways to flash firmware onto an RP2350 microcontroller, each with different prerequisites and use cases.
4+
You can either flash it using the RP2350-built-in bootloader by dragging & dropping the `.uf2` file to the mounted drive, by using the [picotool](https://github.com/raspberrypi/picotool/) tool to talk to the bootloader directly, or by using a hardware debugger or second Pico for programming and debugging over an Serial-Wire-Debug (SWD) connection. The methods are detailed below.
5+
6+
Depending on your preference, you will then learn how to install the tools for these methods in the next chapter. We recommend trying Method 1 first, as it is the easiest to use and doesn't require any installation and setup the other methods later if you need to.
7+
8+
## Method 1: Online Conversion
9+
10+
This method requires no software installation and works entirely through a web browser and your system's file manager.
11+
12+
**Prerequisites:** None
13+
14+
**Steps:**
15+
1. Take your `.elf` file
16+
2. Go to [elf2uf2.yrust.de](https://elf2uf2.yrust.de/)[^1]
17+
3. Upload and convert to `.uf2`
18+
4. Put RP2350 into boot mode:
19+
- Hold **BOOTSEL** button
20+
- Power on
21+
- Release **BOOTSEL**
22+
5. Drag & drop the `.uf2` file to the mounted drive
23+
6. Device will automatically reset and run
24+
25+
## Method 2: Bootloader and picotool
26+
27+
This method uses the official Raspberry Pi tool for direct flashing.
28+
29+
**Prerequisites:** [picotool](https://github.com/raspberrypi/picotool/) installed
30+
31+
**Steps:**
32+
1. Put RP2350 into boot mode:
33+
- Hold **BOOTSEL** button
34+
- Power on
35+
- Release **BOOTSEL**
36+
2. Flash directly with picotool:
37+
```bash
38+
picotool load -u -v -x -t elf your_file.elf
39+
```
40+
3. Device will automatically reset and run
41+
42+
## Method 3: Debug Probe
43+
44+
This method uses a hardware debugger or second Pico for programming and debugging.
45+
46+
**Prerequisites:** Debugger or second Pico + [probe-rs](https://probe.rs/) installed
47+
48+
**Steps:**
49+
1. Connect debugger or second Pico to target RP2350
50+
2. Flash and run with probe-rs:
51+
```bash
52+
probe-rs run --chip RP235x --protocol swd your_file.elf
53+
```
54+
3. Device will be programmed and start running automatically
55+
56+
## Additional Notes
57+
58+
To erase the flash, you can use `picotool erase` or drag & drop the flash nuke utility: [flash_nuke.uf2](https://datasheets.raspberrypi.com/soft/flash_nuke.uf2) (direct download, 96 kB)
59+
60+
[^1]: Our online tool [elf2uf2.yrust.de](https://elf2uf2.yrust.de/) simply executes `picotool uf2 convert your_file.elf your_file.uf2` - it's equivalent to having picotool installed locally but runs in the browser.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Setting Up Your Rust Embedded Toolchain
2+
3+
Before writing any code, we need to configure our development environment for cross-compiling to the RP2350 microcontroller. The RP2350 is a **dual-core ARM Cortex-M33** microcontroller (with some special features we’ll discuss later). Rust, via `rustup`, can target this architecture easily.
4+
5+
1. **Install Rust (stable)** if you haven’t already, via [rustup](https://rustup.rs/). Ensure you also have Cargo, which comes with Rust.
6+
2. **Update Rust** to the latest stable version and self-update rustup (to avoid any surprises):
7+
```bash
8+
rustup self update
9+
rustup update stable
10+
```
11+
3. **Add the target for RP2350:** The Cortex-M33 core uses the ARMv8-M architecture with hardware floating-point. The correct Rust target triple is `thumbv8m.main-none-eabihf`. We’ll add that, and for completeness also add the ARMv6-M target used by older Pico (RP2040) and the RISC-V target (the RP2350 has a RISC-V mode, as we’ll mention). Run:
12+
```bash
13+
rustup target add thumbv6m-none-eabi # (for RP2040, if needed)
14+
rustup target add thumbv8m.main-none-eabihf # RP2350 Arm Cortex-M33
15+
rustup target add riscv32imac-unknown-none-elf # (RP2350 RISC-V mode)
16+
```
17+
> **Note:** The RP2350 is unique in that each core can actually run as either an ARM Cortex-M33 or a RISC-V core (Hazard3) – a novel feature where the core type can be swapped at runtime . In this guide we’ll focus on the standard Cortex-M (ARM) mode. The RISC-V target is added just in case and for future exploration.
18+
19+
With these tools you will already be able to turn valid Rust code into a `.elf` file, which you can then flash onto the RP2350 using the methods described in the next chapter.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Starting a New Project – Blinky (RP2350 Template)
2+
3+
Next, we’ll start a new Rust project for the Raspberry Pi Pico 2 board. The community provides ready-to-go templates for Rust on these boards, which set up all the necessary bits (memory layout, linker script, HAL dependencies, and so on). We will use the official **rp-rs project template** for RP2350.

src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Getting Started With Embedded Rust 📟🦀
2+
3+
This is a free book about Embedded Rust on the Raspberry Pi Pico 2 (with the RP2350 microcontroller). We primarily use this internally at Systemscape, but we hope it can be useful to others as well and invite you to use it as well and contribute to it.

0 commit comments

Comments
 (0)