Skip to content

Commit

Permalink
Unify examples
Browse files Browse the repository at this point in the history
This PR merges the chip specific examples into one folder, inside the
esp-wifi project.

To simplify building, alias' have been added to
`esp-wifi/.cargo/config.toml` per chip to automatically select the right
target and enable the chip feature.

Add build script detection for invalid features

Fix CI, use build instead of check to detect linker errors

enable async feature of hal, this breaks because of interrupt definition for systimer

upgrade hal rev

upgrade hal rev c6

undo binding modifications

fix esp now

fix esp coex

use released hals, update async examples

sync example names

sync example names

Update examples.md

Document alias

update build alias
  • Loading branch information
MabezDev committed Nov 1, 2023
1 parent 316e9a5 commit dbe4b15
Show file tree
Hide file tree
Showing 96 changed files with 439 additions and 8,786 deletions.
123 changes: 37 additions & 86 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,102 +40,53 @@ jobs:
- name: check-fmt
run: cargo fmt --check

checks-xtensa:
builds:
strategy:
matrix:
chip: ["esp32", "esp32s2", "esp32s3"]
chip: ["esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c6"]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: esp-rs/[email protected]
with:
default: true
buildtargets: ${{ matrix.chip }}
ldproxy: false
- uses: Swatinem/rust-cache@v1

- name: check
run: cd examples-${{ matrix.chip }} && cargo check
- name: check (common features)
run: cd examples-${{ matrix.chip }} && cargo check --features=async,wifi,esp-now,embassy-net,log
- name: check (common features + defmt)
run: cd examples-${{ matrix.chip }} && cargo check --no-default-features --features=${{ matrix.chip }},async,wifi,esp-now,embassy-net,defmt
- name: check (dhcp)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=dhcp --features=wifi
- name: check (static_ip)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=static_ip --features=wifi
- name: check (esp_now)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=esp_now --features=esp-now
- name: check (embassy_esp_now)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_esp_now --features=async,esp-now
- name: check (embassy_esp_now_duplex)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_esp_now_duplex --features=async,esp-now
- name: check (embassy_dhcp)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_dhcp --features=async,wifi,embassy-net
- name: check (embassy_access_point)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_access_point --features=async,wifi,embassy-net
- name: build
run: cd esp-wifi && cargo b${{ matrix.chip }}
- name: build (common features)
run: cd esp-wifi && cargo b${{ matrix.chip }} --features=async,wifi,esp-now,embassy-net,log,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (common features + defmt)
run: cd esp-wifi && cargo b${{ matrix.chip }} --no-default-features --features=async,wifi,esp-now,embassy-net,defmt,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (dhcp)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=dhcp --features=wifi
- name: build (static_ip)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=static_ip --features=wifi
- name: build (esp_now)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=esp_now --features=esp-now
- name: build (embassy_esp_now)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=embassy_esp_now --features=async,esp-now,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (embassy_esp_now_duplex)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=embassy_esp_now_duplex --features=async,esp-now,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (embassy_dhcp)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=embassy_dhcp --features=async,wifi,embassy-net,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (embassy_access_point)
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=embassy_access_point --features=async,wifi,embassy-net,${{ matrix.chip }}-hal/embassy-time-timg0

- name: check (common features + ble)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo check --features=async,wifi,ble,esp-now,embassy-net,log
- name: check (common features + ble + defmt)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo check --no-default-features --features=${{ matrix.chip }},async,wifi,ble,esp-now,embassy-net,defmt
- name: check (ble)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo build --release --example=ble --features=ble
- name: check (async_ble)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo build --release --example=async_ble --features=async,ble
- name: check (coex)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo build --release --example=coex --features=wifi,ble,coex

checks-riscv:
strategy:
matrix:
chip: ["esp32c2", "esp32c3", "esp32c6"]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imc-unknown-none-elf
toolchain: nightly-2023-05-16
components: rust-src,rustfmt
- uses: Swatinem/rust-cache@v1

- name: check
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 check
- name: check (common features)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 check --features=async,wifi,esp-now,embassy-net,log
- name: check (common features + defmt)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 check --no-default-features --features=${{ matrix.chip }},async,wifi,esp-now,embassy-net,defmt
- name: check (dhcp)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=dhcp --features=wifi
- name: check (static_ip)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=static_ip --features=wifi
- name: check (esp_now)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=esp_now --features=esp-now
- name: check (embassy_esp_now)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_esp_now --features=async,esp-now
- name: check (embassy_esp_now_duplex)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_esp_now_duplex --features=async,esp-now
- name: check (embassy_dhcp)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_dhcp --features=async,wifi,embassy-net
- name: check (embassy_access_point)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_access_point --features=async,wifi,embassy-net

- name: check (common features + ble)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 check --features=async,wifi,ble,esp-now,embassy-net,log
- name: check (common features + ble + defmt)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 check --no-default-features --features=${{ matrix.chip }},async,wifi,ble,esp-now,embassy-net,defmt
- name: check (ble)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=ble --features=ble
- name: check (async_ble)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=async_ble --features=async,ble
- name: check (coex)
if: ${{ matrix.chip == 'esp32c3' }}
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=coex --features=wifi,ble,coex
- name: build (common features + ble)
if: ${{ matrix.chip != 'esp32s2' }}
run: cd esp-wifi && cargo b${{ matrix.chip }} --features=async,wifi,ble,esp-now,embassy-net,log,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (common features + ble + defmt)
if: ${{ matrix.chip != 'esp32s2' }}
run: cd esp-wifi && cargo b${{ matrix.chip }} --no-default-features --features=async,wifi,ble,esp-now,embassy-net,defmt,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (ble)
if: ${{ matrix.chip != 'esp32s2' }}
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=ble --features=ble
- name: build (embassy_ble)
if: ${{ matrix.chip != 'esp32s2' }}
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=embassy_ble --features=async,ble,${{ matrix.chip }}-hal/embassy-time-timg0
- name: build (coex)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' || matrix.chip == 'esp32c3' }}
run: cd esp-wifi && cargo b${{ matrix.chip }} --release --example=coex --features=wifi,ble,coex
24 changes: 7 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ members = [
"esp-wifi",
"esp-wifi-sys",
"xtask",
"examples-esp32c2",
"examples-esp32c3",
"examples-esp32c6",
"examples-esp32",
"examples-esp32s2",
"examples-esp32s3",
]
exclude = [
"extras/esp-wifishark",
Expand All @@ -27,12 +21,12 @@ lto = "off"

[workspace.dependencies]
defmt = "=0.3.5"
esp32c3-hal = { version = "0.12.0" }
esp32c2-hal = { version = "0.10.0" }
esp32c6-hal = { version = "0.5.0" }
esp32-hal = { version = "0.15.0" }
esp32s3-hal = { version = "0.12.0" }
esp32s2-hal = { version = "0.12.0" }
esp32c3-hal = { version = "0.13.0" }
esp32c2-hal = { version = "0.11.0" }
esp32c6-hal = { version = "0.6.0" }
esp32-hal = { version = "0.16.0" }
esp32s3-hal = { version = "0.13.0" }
esp32s2-hal = { version = "0.13.0" }
smoltcp = { version = "0.10.0", default-features=false, features = ["proto-igmp", "proto-ipv4", "proto-dns", "socket-tcp", "socket-icmp", "socket-udp", "socket-dns", "medium-ethernet", "proto-dhcpv4", "socket-raw", "socket-dhcpv4"] }
critical-section = "1.1.1"
atomic-polyfill = "1.0.2"
Expand All @@ -53,6 +47,7 @@ embassy-net-driver = { version = "0.1.0" }
toml-cfg = "0.1.3"
libm = "0.2.7"
cfg-if = "1.0.0"
static_cell = { version = "1", features = ["nightly"] }

embassy-net = { version = "0.1.0", features = ["nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "b82f1e7009bef7e32f0918be5b186188aa5e7109", features = ["macros"] }
Expand All @@ -62,8 +57,3 @@ futures-util = { version = "0.3.28", default-features = false }
esp-println = { version = "0.6.0" }
esp-backtrace = { version = "0.8.0", features = ["panic-handler", "exception-handler", "print-uart"] }
embedded-hal-async = { version = "1.0.0-rc.1" }

# patching esp32c6-hal for BLE - it would compile with 0.5.0 but not work
[patch.crates-io]
esp32c6-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "4c34ebe9e264fcc31fabba862274adae8daa680a" }
esp-hal-common = { git = "https://github.com/esp-rs/esp-hal.git", rev = "4c34ebe9e264fcc31fabba862274adae8daa680a" }
60 changes: 29 additions & 31 deletions esp-wifi/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# Alias' for quickly building for different chips or running examples
# By default we enable
# - `embassy-time-timg0` as the examples assume we are using this time driver
# - `embassy-executor-thread` on Xtensa chips to take advantage of the Xtensa specific executor we have in esp-hal
[alias]
esp32 = "run --features esp32 --target xtensa-esp32-none-elf --features esp32-hal/embassy-time-timg0,esp32-hal/embassy-executor-thread"
esp32s2 = "run --features esp32s2 --target xtensa-esp32s2-none-elf --features esp32s2-hal/embassy-time-timg0,esp32s2-hal/embassy-executor-thread"
esp32s3 = "run --features esp32s3 --target xtensa-esp32s3-none-elf --features esp32s3-hal/embassy-time-timg0,esp32s3-hal/embassy-executor-thread"
esp32c2 = "run --features esp32c2 --target riscv32imc-unknown-none-elf --features esp32c2-hal/embassy-time-timg0"
esp32c3 = "run --features esp32c3 --target riscv32imc-unknown-none-elf --features esp32c3-hal/embassy-time-timg0"
esp32c6 = "run --features esp32c6 --target riscv32imac-unknown-none-elf --features esp32c6-hal/embassy-time-timg0"

besp32 = "build --features esp32 --target xtensa-esp32-none-elf --features esp32-hal/embassy-time-timg0,esp32-hal/embassy-executor-thread"
besp32s2 = "build --features esp32s2 --target xtensa-esp32s2-none-elf --features esp32s2-hal/embassy-time-timg0,esp32s2-hal/embassy-executor-thread"
besp32s3 = "build --features esp32s3 --target xtensa-esp32s3-none-elf --features esp32s3-hal/embassy-time-timg0,esp32s3-hal/embassy-executor-thread"
besp32c2 = "build --features esp32c2 --target riscv32imc-unknown-none-elf --features esp32c2-hal/embassy-time-timg0"
besp32c3 = "build --features esp32c3 --target riscv32imc-unknown-none-elf --features esp32c3-hal/embassy-time-timg0"
besp32c6 = "build --features esp32c6 --target riscv32imac-unknown-none-elf --features esp32c6-hal/embassy-time-timg0"

[target.riscv32imc-unknown-none-elf]
runner = "espflash flash --monitor"

rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",

"-C", "force-frame-pointers",

# Enable the atomic codegen option for RISCV
"-C", "target-feature=+a",

# tell the core library have atomics even though it's not specified in the target definition
"--cfg", "target_has_atomic_load_store",
"--cfg", 'target_has_atomic_load_store="8"',
Expand All @@ -23,72 +44,49 @@ rustflags = [

[target.riscv32imac-unknown-none-elf]
runner = "espflash flash --monitor"

rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",

"-C", "force-frame-pointers",

# tell the core library have atomics even though it's not specified in the target definition
"--cfg", "target_has_atomic_load_store",
"--cfg", 'target_has_atomic_load_store="8"',
"--cfg", 'target_has_atomic_load_store="16"',
"--cfg", 'target_has_atomic_load_store="32"',
"--cfg", 'target_has_atomic_load_store="ptr"',
# enable cas
"--cfg", "target_has_atomic",
"--cfg", 'target_has_atomic="8"',
"--cfg", 'target_has_atomic="16"',
"--cfg", 'target_has_atomic="32"',
"--cfg", 'target_has_atomic="ptr"',
]

[target.xtensa-esp32-none-elf]
runner = "espflash flash --monitor"

rustflags = [
#"-C", "linker=rust-lld",

"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",
]

[target.xtensa-esp32s3-none-elf]
runner = "espflash flash --monitor"

rustflags = [
#"-C", "linker=rust-lld",

"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",

# for now disable loop optimization
"-C", "target-feature=-loop",
]

[target.xtensa-esp32s2-none-elf]
runner = "espflash flash --monitor"

rustflags = [
#"-C", "linker=rust-lld",

"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",

# Enable the atomic codegen option for Xtensa
"-C", "target-feature=+s32c1i",

# tell the core library have atomics even though it's not specified in the target definition
"--cfg", "target_has_atomic_load_store",
"--cfg", 'target_has_atomic_load_store="8"',
"--cfg", 'target_has_atomic_load_store="16"',
"--cfg", 'target_has_atomic_load_store="32"',
"--cfg", 'target_has_atomic_load_store="ptr"',
# Tell the `core` library that we have atomics, even though it's not
# specified in the target definition
"--cfg", 'target_has_atomic',
"--cfg", 'target_has_atomic="8"',
"--cfg", 'target_has_atomic="16"',
"--cfg", 'target_has_atomic="32"',
"--cfg", 'target_has_atomic="ptr"',
]

[build]
target = "riscv32imc-unknown-none-elf"

[unstable]
build-std = [ "core" ]
36 changes: 30 additions & 6 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,33 @@ atomic_enum = { workspace = true }
[build-dependencies]
toml-cfg.workspace = true

[dev-dependencies]
esp-println = { workspace = true, features = ["log"] }
esp-backtrace = { workspace = true }
embedded-svc.workspace = true
embassy-executor = { workspace = true }
embassy-time.workspace = true
embassy-futures.workspace = true
futures-util.workspace = true
embassy-net = { workspace = true }
embassy-sync.workspace = true
bleps.workspace = true
embedded-io.workspace = true
embedded-hal-async = { workspace = true }
log = { workspace = true }
smoltcp.workspace = true
static_cell = { workspace = true }

[features]
default = [ "utils", "log" ]

# chip features
esp32c2 = [ "esp32c2-hal", "esp-wifi-sys/esp32c2" ]
esp32c3 = [ "esp32c3-hal", "esp-wifi-sys/esp32c3" ]
esp32c6 = [ "esp32c6-hal", "esp-wifi-sys/esp32c6" ]
esp32 = [ "esp32-hal", "esp-wifi-sys/esp32" ]
esp32s2 = [ "esp32s2-hal", "esp-wifi-sys/esp32s2" ]
esp32s3 = [ "esp32s3-hal", "esp-wifi-sys/esp32s3" ]
esp32c2 = [ "esp32c2-hal", "esp-wifi-sys/esp32c2", "esp-println/esp32c2", "esp-backtrace/esp32c2", "embassy-executor/arch-riscv32" ]
esp32c3 = [ "esp32c3-hal", "esp-wifi-sys/esp32c3", "esp-println/esp32c3", "esp-backtrace/esp32c3", "embassy-executor/arch-riscv32" ]
esp32c6 = [ "esp32c6-hal", "esp-wifi-sys/esp32c6", "esp-println/esp32c6", "esp-backtrace/esp32c6", "embassy-executor/arch-riscv32" ]
esp32 = [ "esp32-hal", "esp-wifi-sys/esp32", "esp-println/esp32", "esp-backtrace/esp32" ]
esp32s2 = [ "esp32s2-hal", "esp-wifi-sys/esp32s2", "esp-println/esp32s2", "esp-backtrace/esp32s2" ]
esp32s3 = [ "esp32s3-hal", "esp-wifi-sys/esp32s3", "esp-println/esp32s3", "esp-backtrace/esp32s3" ]

# async features
async = [
Expand All @@ -58,6 +75,13 @@ async = [
"esp32-hal?/embassy",
"esp32s2-hal?/embassy",
"esp32s3-hal?/embassy",
"esp32c3-hal?/async",
"esp32c2-hal?/async",
"esp32c6-hal?/async",
"esp32-hal?/async",
"esp32s2-hal?/async",
"esp32s3-hal?/async",
"bleps/async"
]

embassy-net = ["dep:embassy-net-driver", "async"]
Expand Down
18 changes: 18 additions & 0 deletions esp-wifi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
feature = "esp32s3",
))]
fn main() -> Result<(), String> {
#[cfg(all(feature = "ble", feature = "esp32s2"))]
{
panic!(r#"
BLE is not supported on this target.
"#);
}
#[cfg(all(feature = "coex", any(feature = "esp32s2", feature = "esp32c2", feature = "esp32c6")))]
{
panic!(r#"
COEX is not yet supported on this target.
See https://github.com/esp-rs/esp-wifi/issues/92.
"#);
}
match std::env::var("OPT_LEVEL") {
Ok(level) => {
if level != "2" && level != "3" {
Expand Down
Loading

0 comments on commit dbe4b15

Please sign in to comment.