Compare commits

..

10 Commits

21 changed files with 163 additions and 18 deletions
+8 -2
View File
@@ -1,8 +1,14 @@
[target.thumbv6m-none-eabi] [target.thumbv6m-none-eabi]
runner = "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] [build]
target = "thumbv6m-none-eabi" target = "thumbv6m-none-eabi"
[unstable] [unstable]
build-std = ["core", "alloc"] # build-std = ["core", "alloc"]
+6 -3
View File
@@ -1,7 +1,9 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Flash Pico W" type="CargoCommandRunConfiguration" factoryName="Cargo Command"> <configuration default="false" name="Flash Pico W" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --release" /> <option name="buildProfileId" value="release" />
<option name="command" value="run" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" /> <option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" /> <option name="requiredFeatures" value="true" />
@@ -9,7 +11,8 @@
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" /> <option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs /> <option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
</component> </component>
Generated
+33
View File
@@ -181,6 +181,15 @@ dependencies = [
"syn 2.0.117", "syn 2.0.117",
] ]
[[package]]
name = "cortex-m-semihosting"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c23234600452033cc77e4b761e740e02d2c4168e11dbf36ab14a0f58973592b0"
dependencies = [
"cortex-m",
]
[[package]] [[package]]
name = "crc-any" name = "crc-any"
version = "2.5.0" version = "2.5.0"
@@ -329,6 +338,29 @@ dependencies = [
"defmt 0.3.100", "defmt 0.3.100",
] ]
[[package]]
name = "defmt-test"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c1e67ff0e1c6b1a9540a1a3e04454658faacdd188c91987c444d56e469d7dea"
dependencies = [
"cortex-m-rt",
"cortex-m-semihosting",
"defmt 0.3.100",
"defmt-test-macros",
]
[[package]]
name = "defmt-test-macros"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe5520fd36862f281c026abeaab153ebbc001717c29a9b8e5ba9704d8f3a879d"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.117",
]
[[package]] [[package]]
name = "diff" name = "diff"
version = "0.1.13" version = "0.1.13"
@@ -1368,6 +1400,7 @@ dependencies = [
"cyw43-pio", "cyw43-pio",
"defmt 0.3.100", "defmt 0.3.100",
"defmt-rtt", "defmt-rtt",
"defmt-test",
"embassy-executor", "embassy-executor",
"embassy-net", "embassy-net",
"embassy-rp", "embassy-rp",
+14
View File
@@ -18,5 +18,19 @@ cortex-m-rt = "0.7.5"
panic-probe = { version = "0.3.2", features = ["print-defmt"] } panic-probe = { version = "0.3.2", features = ["print-defmt"] }
defmt = "0.3.10" defmt = "0.3.10"
defmt-rtt = "0.4.1" defmt-rtt = "0.4.1"
defmt-test = "0.3.0"
static_cell = "2.1.0" static_cell = "2.1.0"
portable-atomic = { version = "1.11.0", features = ["critical-section"] } portable-atomic = { version = "1.11.0", features = ["critical-section"] }
[lib]
test = false
harness = false
[[bin]]
name = "rusty-dog"
test = false
path = "src/main.rs"
[[test]]
name = "example_test"
harness = false
+23 -3
View File
@@ -1,3 +1,23 @@
DIRENV := $(shell command -v direnv 2> /dev/null)
# If we have direnv and we're not already in the environment, re-exec via direnv
ifdef DIRENV
ifeq ($(origin DIRENV_DIR), undefined)
# Ensure direnv is allowed
_ALLOW := $(shell direnv allow . > /dev/null 2>&1)
# Re-exec make via direnv
EXEC := direnv exec . $(MAKE)
build run test clean flatpak-build:
@$(EXEC) $@
else
# We are already inside direnv, or direnv is not available
EXEC :=
endif
else
EXEC :=
endif
ifndef EXEC
build: build:
cargo build cargo build
@@ -10,10 +30,10 @@ test:
clean: clean:
cargo clean cargo clean
.PHONY: build run test clean
# Flatpak build target # Flatpak build target
.PHONY: flatpak-build .PHONY: flatpak-build
flatpak-build: flatpak-build:
flatpak-builder --force-clean build-flatpak flatpak/app.flatpak.json flatpak-builder --force-clean build-flatpak flatpak/app.flatpak.json
endif
.PHONY: build run test clean
+38 -3
View File
@@ -2,6 +2,18 @@
This project is an embedded Rust application for the Raspberry Pi Pico W, utilizing the Embassy async framework. This project is an embedded Rust application for the Raspberry Pi Pico W, utilizing the Embassy async framework.
## Build Commands
This project uses a `Makefile` to simplify common tasks. The `Makefile` is configured to automatically use `direnv` to load the Nix environment if `direnv` is installed on your system. This ensures that the correct Rust toolchain and dependencies are available even if you haven't manually run `nix develop` or `direnv allow`.
| Command | Description |
|---------|-------------|
| `make build` | Build the project using `cargo build` |
| `make run` | Run the project using `cargo run` |
| `make test` | Run tests using `cargo test` |
| `make clean` | Clean build artifacts |
| `make flatpak-build` | Build the Flatpak package |
## LLM Agent Guidelines ## LLM Agent Guidelines
This project uses LLM agents for configuration and housekeeping. Please refer to [agents.md](agents.md) for the rules and guidelines governing their use. This project uses LLM agents for configuration and housekeeping. Please refer to [agents.md](agents.md) for the rules and guidelines governing their use.
@@ -92,10 +104,33 @@ flatpak run org.example.rustdevshell
This project is configured for seamless flashing from the IDE or terminal. This project is configured for seamless flashing from the IDE or terminal.
### Flashing via USB (BOOTSEL mode)
If you don't have a physical debugger, you can flash the Pico W directly via USB using the BOOTSEL mode:
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. **Cable**: Ensure you are using a data-sync USB cable, not just a charging cable.
### Flashing from IDE ### 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". 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 `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 ### Flashing from Terminal
You can flash the Pico W by running: You can flash the Pico W by running:
@@ -104,10 +139,10 @@ You can flash the Pico W by running:
cargo run --release 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: If you prefer to use a physical debugger (e.g. CMSIS-DAP), you can change the runner in `.cargo/config.toml` to:
`runner = "elf2uf2-rs -d"` `runner = "direnv exec . probe-rs run --chip RP2040"`
## Testing & Development Features ## Testing & Development Features
+1 -1
View File
@@ -44,7 +44,7 @@
rustToolchain = rustToolchain =
with inputs.fenix.packages.${prev.stdenv.hostPlatform.system}; with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
combine ( combine (
with stable; with latest;
[ [
clippy clippy
rustc rustc
+9
View File
@@ -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
}
+1
View File
@@ -8,6 +8,7 @@ pkgs.mkShell {
pkgs.rustfmt pkgs.rustfmt
pkgs.clippy pkgs.clippy
pkgs.rust-analyzer pkgs.rust-analyzer
pkgs.gnumake
]; ];
shellHook = '' shellHook = ''
echo "[shell.nix] Legacy shell for Rust dev. Use 'nix develop' for full flake support." echo "[shell.nix] Legacy shell for Rust dev. Use 'nix develop' for full flake support."
View File
View File
View File
View File
+4
View File
@@ -0,0 +1,4 @@
#![no_std]
// Logic and hardware-independent code goes here.
// This allows you to run `cargo test` on your host machine.
+11 -2
View File
@@ -1,3 +1,12 @@
fn main() { #![no_std]
println!("Hello from Rust skeletal app. Edit src/main.rs to get started!"); #![no_main]
use defmt_rtt as _;
use embassy_executor::Spawner;
use embassy_rp as _;
use panic_probe as _;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
defmt::info!("Hello from the Pico W!");
} }
View File
+2
View File
@@ -0,0 +1,2 @@
mod mqtt;
mod wifi;
View File
View File
+13
View File
@@ -0,0 +1,13 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use panic_probe as _;
#[defmt_test::tests]
mod tests {
#[test]
fn it_works() {
assert!(true);
}
}
-4
View File
@@ -1,4 +0,0 @@
#[test]
fn test_sample() {
assert_eq!(1, 1);
}