From d874a771bbc86bb8e1e1b3fe992dbf215731a878 Mon Sep 17 00:00:00 2001 From: Paul Sbarra Date: Sat, 28 Dec 2024 22:06:09 -0600 Subject: [PATCH 1/2] [avr] executor example --- .vscode/settings.json | 4 +++- embassy-executor/Cargo.toml | 2 +- examples/avr/.cargo/config.toml | 8 ++++++++ examples/avr/Cargo.toml | 22 ++++++++++++++++++++++ examples/avr/README.md | 15 +++++++++++++++ examples/avr/rust-toolchain.toml | 4 ++++ examples/avr/src/bin/blinky.rs | 13 +++++++++++++ rust-toolchain-nightly.toml | 1 + 8 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 examples/avr/.cargo/config.toml create mode 100644 examples/avr/Cargo.toml create mode 100644 examples/avr/README.md create mode 100644 examples/avr/rust-toolchain.toml create mode 100644 examples/avr/src/bin/blinky.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 48d0957e61..1372dc24b0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "rust-analyzer.cargo.noDefaultFeatures": true, "rust-analyzer.showUnlinkedFileNotification": false, // Uncomment the target of your chip. + //"rust-analyzer.cargo.target": "avr-unknown-gnu-atmega328", //"rust-analyzer.cargo.target": "thumbv6m-none-eabi", //"rust-analyzer.cargo.target": "thumbv7m-none-eabi", "rust-analyzer.cargo.target": "thumbv7em-none-eabi", @@ -28,6 +29,7 @@ // To work on the examples, comment the line above and all of the cargo.features lines, // then uncomment ONE line below to select the chip you want to work on. // This makes rust-analyzer work on the example crate and all its dependencies. + // "examples/avr/Cargo.toml", // "examples/nrf52840-rtic/Cargo.toml", // "examples/nrf5340/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", @@ -54,4 +56,4 @@ // "examples/stm32wl/Cargo.toml", // "examples/wasm/Cargo.toml", ], -} +} \ No newline at end of file diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index d6f24ce846..d7dcd75693 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -50,7 +50,7 @@ wasm-bindgen = { version = "0.2.82", optional = true } js-sys = { version = "0.3", optional = true } # arch-avr dependencies -avr-device = { version = "0.5.3", optional = true } +avr-device = { version = "0.5.3", features = ["critical-section-impl", "rt"], optional = true } [dev-dependencies] critical-section = { version = "1.1", features = ["std"] } diff --git a/examples/avr/.cargo/config.toml b/examples/avr/.cargo/config.toml new file mode 100644 index 0000000000..1fe34da044 --- /dev/null +++ b/examples/avr/.cargo/config.toml @@ -0,0 +1,8 @@ +[build] +target = "avr-unknown-gnu-atmega328" + +[target.'cfg(target_arch = "avr")'] +runner = "ravedude uno -cb 57600" + +[unstable] +build-std = ["core"] \ No newline at end of file diff --git a/examples/avr/Cargo.toml b/examples/avr/Cargo.toml new file mode 100644 index 0000000000..6140ef1ace --- /dev/null +++ b/examples/avr/Cargo.toml @@ -0,0 +1,22 @@ +[package] +edition = "2021" +name = "embassy-avr-examples" +version = "0.1.0" +license = "MIT OR Apache-2.0" + +[dependencies] +avr-device = { version = "0.5", features = ["atmega328p"] } +embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-avr", "executor-thread", "nightly"] } +panic-halt = "1" + +[profile.dev] +panic = "abort" +lto = true +opt-level = "s" + +[profile.release] +panic = "abort" +codegen-units = 1 +debug = true +lto = true +opt-level = "s" \ No newline at end of file diff --git a/examples/avr/README.md b/examples/avr/README.md new file mode 100644 index 0000000000..615c5dc9ac --- /dev/null +++ b/examples/avr/README.md @@ -0,0 +1,15 @@ +# Examples for AVR microcontrollers +Run individual examples with +``` +cargo run --bin --release +``` +for example +``` +cargo run --bin blinky +``` + +## Checklist before running examples +You may need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using. + +* [ ] Update `.cargo/config.toml` with the correct target and runner command for your hardware. (use `ravedude --help` to list supported boards) +* [ ] Update `Cargo.toml` to use the correct `avr-device` feature for your processor. \ No newline at end of file diff --git a/examples/avr/rust-toolchain.toml b/examples/avr/rust-toolchain.toml new file mode 100644 index 0000000000..5ff0b3ecd7 --- /dev/null +++ b/examples/avr/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2024-12-10" +components = ["rust-src"] +profile = "minimal" \ No newline at end of file diff --git a/examples/avr/src/bin/blinky.rs b/examples/avr/src/bin/blinky.rs new file mode 100644 index 0000000000..d318bafe11 --- /dev/null +++ b/examples/avr/src/bin/blinky.rs @@ -0,0 +1,13 @@ +#![no_std] +#![no_main] +#![feature(impl_trait_in_assoc_type)] + +use embassy_executor::Spawner; +use panic_halt as _; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + loop { + // TODO + } +} diff --git a/rust-toolchain-nightly.toml b/rust-toolchain-nightly.toml index 6efd98956c..ec1831f73f 100644 --- a/rust-toolchain-nightly.toml +++ b/rust-toolchain-nightly.toml @@ -2,6 +2,7 @@ channel = "nightly-2024-12-10" components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ] targets = [ + "avr-unknown-gnu-atmega328", "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", From 0578870f7606b7a92860a2892a9446a647eb3c8b Mon Sep 17 00:00:00 2001 From: Paul Sbarra Date: Sun, 29 Dec 2024 22:47:55 -0600 Subject: [PATCH 2/2] [avr] bump avr-device to version 0.6 --- embassy-executor/Cargo.toml | 2 +- examples/avr/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index d7dcd75693..f51c2c1dcc 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -50,7 +50,7 @@ wasm-bindgen = { version = "0.2.82", optional = true } js-sys = { version = "0.3", optional = true } # arch-avr dependencies -avr-device = { version = "0.5.3", features = ["critical-section-impl", "rt"], optional = true } +avr-device = { version = "0.6", features = ["critical-section-impl", "rt"], optional = true } [dev-dependencies] critical-section = { version = "1.1", features = ["std"] } diff --git a/examples/avr/Cargo.toml b/examples/avr/Cargo.toml index 6140ef1ace..5992b5ec59 100644 --- a/examples/avr/Cargo.toml +++ b/examples/avr/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -avr-device = { version = "0.5", features = ["atmega328p"] } +avr-device = { version = "0.6", features = ["atmega328p"] } embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-avr", "executor-thread", "nightly"] } panic-halt = "1"