Skip to content

Commit

Permalink
Merge pull request #201 from bytedream/esp32-example-improvements
Browse files Browse the repository at this point in the history
Update esp32 example for non esp32c3 targets
  • Loading branch information
lulf authored Dec 18, 2024
2 parents 2357bde + 85326e1 commit aaf2d02
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
30 changes: 20 additions & 10 deletions examples/esp32/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
[target.riscv32imc-unknown-none-elf]
runner = "espflash flash --monitor"

[alias]
esp32 = "run --release --no-default-features --features=esp32 --target=xtensa-esp32-none-elf"
esp32c2 = "run --release --no-default-features --features=esp32c2 --target=riscv32imc-unknown-none-elf"
esp32c3 = "run --release --no-default-features --features=esp32c3 --target=riscv32imc-unknown-none-elf"
esp32c6 = "run --release --no-default-features --features=esp32c6 --target=riscv32imac-unknown-none-elf"
esp32h2 = "run --release --no-default-features --features=esp32h2 --target=riscv32imac-unknown-none-elf"
esp32s3 = "run --release --no-default-features --features=esp32s3 --target=xtensa-esp32s3-none-elf"

[env]
ESP_LOG = "info"
[target.'cfg(all(any(target_arch = "riscv32imc", target_arch = "riscv32imac", target_arch = "xtensa"), target_os = "none"))']
runner = "espflash flash --monitor"

[build]
# Pick ONE of these compilation targets
# target = "xtensa-esp32-none-elf" # ESP32
# target = "xtensa-esp32s3-none-elf" # ESP32-S3
target = "riscv32imc-unknown-none-elf" # ESP32-C2 and ESP32-C3
# target = "riscv32imac-unknown-none-elf" # ESP32-C6 and ESP32-H2

rustflags = [
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code
"-C",
"force-frame-pointers",
"-C", "force-frame-pointers",
]

target = "riscv32imc-unknown-none-elf"

[unstable]
build-std = ["core"]
build-std = ["alloc", "core"]

[env]
ESP_LOG = "info"
27 changes: 12 additions & 15 deletions examples/esp32/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions examples/esp32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
embassy-executor = { version = "0.6.0", features = ["task-arena-size-65536"] }
embassy-executor = { version = "0.6.0", features = ["task-arena-size-32768"] }
esp-backtrace = { version = "0.14.2", features = [
"esp32c3",
"exception-handler",
"panic-handler",
"println",
Expand All @@ -31,11 +30,11 @@ embassy-sync = "0.6"

[features]
default = ["esp32c3"]
esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-hal-embassy/esp32", "esp-println/esp32", "esp-wifi/esp32"]
esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-hal-embassy/esp32c2", "esp-println/esp32c2", "esp-wifi/esp32c2"]
esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-hal-embassy/esp32c3", "esp-println/esp32c3", "esp-wifi/esp32c3"]
esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-hal-embassy/esp32c6", "esp-println/esp32c6", "esp-wifi/esp32c6"]
esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-hal-embassy/esp32h2", "esp-println/esp32h2", "esp-wifi/esp32h2"]
esp32s2 = ["esp-hal/esp32s2", "esp-backtrace/esp32s2", "esp-hal-embassy/esp32s2", "esp-println/esp32s2", "esp-wifi/esp32s2"]
esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-hal-embassy/esp32s3", "esp-println/esp32s3", "esp-wifi/esp32s3"]

[profile.dev]
Expand Down
2 changes: 1 addition & 1 deletion examples/esp32/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("cargo:rustc-link-arg-bins=-Tlinkall.x");
}
}
13 changes: 10 additions & 3 deletions examples/esp32/src/bin/ble_bas_peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ async fn main(_s: Spawner) {
)
.unwrap();

let systimer =
esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER).split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(systimer.alarm0);
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}

let bluetooth = peripherals.BT;
let connector = BleConnector::new(&init, bluetooth);
Expand Down

0 comments on commit aaf2d02

Please sign in to comment.