Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[avr] create initial example #3696

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -54,4 +56,4 @@
// "examples/stm32wl/Cargo.toml",
// "examples/wasm/Cargo.toml",
],
}
}
2 changes: 1 addition & 1 deletion embassy-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.6", features = ["critical-section-impl", "rt"], optional = true }

[dev-dependencies]
critical-section = { version = "1.1", features = ["std"] }
Expand Down
8 changes: 8 additions & 0 deletions examples/avr/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
target = "avr-unknown-gnu-atmega328"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the example directory name more closely match the rustc target (avr -> atmega328)?

Currently nightly only supports this target, but avr-hal maintains some additional spec files. I'm unsure if these will all end up being their own rustc platforms, if they can drop the gnu dependency, or if they can be consolidated under a more generic name.

I'm assuming any AVR support here would only use rustc supported targets, otherwise this repo would likely need to duplicate the spec files.

Copy link
Contributor Author

@tones111 tones111 Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've learned of some progress regarding rustc avr target support.
rust-lang/rust#131651

The proposal consolidates the avr processors into one avr-unknown-unknown or avr-unknown-none target.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i put "avr-unknown-gnu-atmega328" just because it was there, i think most of the times, you'll be using target jsons from avr-hal


[target.'cfg(target_arch = "avr")']
runner = "ravedude uno -cb 57600"

[unstable]
build-std = ["core"]
22 changes: 22 additions & 0 deletions examples/avr/Cargo.toml
tones111 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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.6", 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"
15 changes: 15 additions & 0 deletions examples/avr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Examples for AVR microcontrollers
Run individual examples with
```
cargo run --bin <module-name> --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.
4 changes: 4 additions & 0 deletions examples/avr/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2024-12-10"
components = ["rust-src"]
profile = "minimal"
13 changes: 13 additions & 0 deletions examples/avr/src/bin/blinky.rs
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toggling a pin using avr-device is easy enough, but the big hang up here is lack of an AVR time driver.

Is there interest in implementing/supporting an embassy-specific AVR hal, or should the examples make use of avr-hal? Does embassy attempt to have a consistent feel across its HALs?

One challenge is that none of the AVR HAL crates have been published, so git dependencies are needed. I'm also unsure how well it's design aligns with the HALs here.

}
}
1 change: 1 addition & 0 deletions rust-toolchain-nightly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down