From b2c8d0d935ccb523f8987d4def50fb67433d0184 Mon Sep 17 00:00:00 2001 From: Kyle J Turpin Date: Thu, 4 Jun 2026 18:40:44 -0500 Subject: [PATCH] Update flake.nix to use latest Rust toolchain --- .cargo/config.toml | 8 +++++++- README.md | 32 +++++++++++++++++++++----------- memory.x | 9 +++++++++ src/main.rs | 1 + 4 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 memory.x diff --git a/.cargo/config.toml b/.cargo/config.toml index d1ef37b..ab992e8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,11 @@ [target.thumbv6m-none-eabi] -runner = "direnv exec . probe-rs run --chip RP2040" +runner = "direnv exec . elf2uf2-rs -d" +rustflags = [ + "-C", "linker=rust-lld", + "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tlink-rp.x", + "-C", "link-arg=-Tdefmt.x", +] [build] target = "thumbv6m-none-eabi" diff --git a/README.md b/README.md index d544f5a..7a5c7d6 100644 --- a/README.md +++ b/README.md @@ -104,22 +104,32 @@ flatpak run org.example.rustdevshell This project is configured for seamless flashing from the IDE or terminal. -### Troubleshooting: No Connected Probes +### Flashing via USB (BOOTSEL mode) -If you encounter the error `Error: No connected probes were found` or udev rule warnings, check the following: +If you don't have a physical debugger, you can flash the Pico W directly via USB using the BOOTSEL mode: -1. **Hardware Connection**: Ensure your Raspberry Pi Pico W is connected via a compatible debugger (e.g., another Pico running `picoprobe`, a CMSIS-DAP debugger, or an ESP-Prog). -2. **Udev Rules (Linux)**: `probe-rs` needs permission to access the USB device. - - Create a file named `/etc/udev/rules.d/69-probe-rs.rules`. - - Add the rules provided by the [probe-rs documentation](https://probe.rs/docs/getting-started/probe-setup/). +1. **Enter BOOTSEL Mode**: Hold the `BOOTSEL` button on your Pico W while plugging it into your computer's USB port. It should appear as a USB mass storage device. +2. **Flash and Run**: Run the following command (or use the IDE "Run" button): + ```bash + cargo run --release + ``` + This project is configured to use `elf2uf2-rs`, which automatically detects the Pico W in BOOTSEL mode, converts the binary to UF2 format, and flashes it. + +### Troubleshooting: Flashing Issues + +If you encounter issues flashing via USB: +1. **Check BOOTSEL mode**: Ensure the Pico W is mounted as a USB drive. +2. **Udev Rules (Linux)**: You may need permissions to access the USB device. + - Create a file named `/etc/udev/rules.d/99-pico.rules`. + - Add: `SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE="0666"` - Reload rules: `sudo udevadm control --reload` and `sudo udevadm trigger`. -3. **Group Membership**: Ensure your user is in the `plugdev` or `dialout` group (depending on your distro's udev rules). +3. **Cable**: Ensure you are using a data-sync USB cable, not just a charging cable. ### Flashing from IDE If you are using **RustRover** or **IntelliJ Rust**, you can use the "Flash Pico W" run configuration provided in the `.run` folder. Just select it from the run menu and click "Run". -**Note:** The project is configured to use `direnv exec .` in `.cargo/config.toml` to ensure `probe-rs` is available. Ensure `direnv` is installed and allowed (`direnv allow`) on your system. For the best experience, we recommend installing the **direnv** plugin for your IDE. +**Note:** The project is configured to use `direnv exec .` in `.cargo/config.toml` to ensure `elf2uf2-rs` is available. Ensure `direnv` is installed and allowed (`direnv allow`) on your system. For the best experience, we recommend installing the **direnv** plugin for your IDE. ### Flashing from Terminal @@ -129,10 +139,10 @@ You can flash the Pico W by running: cargo run --release ``` -This uses `probe-rs` (configured in `.cargo/config.toml`) to flash and run the binary via a CMSIS-DAP debugger or similar. +This uses `elf2uf2-rs` (configured in `.cargo/config.toml`) to flash the binary via the USB BOOTSEL mode. -If you prefer to use the UF2 bootloader (dragging to the drive or using `elf2uf2-rs`), you can change the runner in `.cargo/config.toml` to: -`runner = "elf2uf2-rs -d"` +If you prefer to use a physical debugger (e.g. CMSIS-DAP), you can change the runner in `.cargo/config.toml` to: +`runner = "direnv exec . probe-rs run --chip RP2040"` ## Testing & Development Features diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..0387638 --- /dev/null +++ b/memory.x @@ -0,0 +1,9 @@ +MEMORY +{ + /* FLASH and RAM lengths must match the RP2040 */ + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + RAM : ORIGIN = 0x20000000, LENGTH = 256K + SCRATCH_A : ORIGIN = 0x20040000, LENGTH = 4K + SCRATCH_B : ORIGIN = 0x20041000, LENGTH = 4K +} diff --git a/src/main.rs b/src/main.rs index 18aefc5..c14a549 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use defmt_rtt as _; use embassy_executor::Spawner; +use embassy_rp as _; use panic_probe as _; #[embassy_executor::main]