Skip to content

Commit

Permalink
chore: Update esp-hal, esp-wifi. Use esp_alloc for network stack (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyGrondin authored Oct 15, 2024
1 parent 63eabf6 commit e6e698f
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rustflags = [
]

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

[alias]
xtask = "run --manifest-path ./xtask/Cargo.toml --"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imc-unknown-none-elf
toolchain: nightly-2024-06-12
toolchain: nightly-2024-07-22
components: rust-src,rustfmt
- uses: esp-rs/xtensa-toolchain@v1.5
with:
Expand Down
18 changes: 11 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ lto = false
opt-level = 3

[dependencies]
esp-hal = { version = "0.20.1" }
esp-hal = { version = "0.21.0" }
esp-backtrace = { version = "0.14.0", features = [
"panic-handler",
"println",
"exception-handler",
] }
esp-println = { version = "0.11.0", features = ["log"] }
esp-hal-embassy = { version = "0.3.0", optional = true }
esp-println = { version = "0.12.0", features = ["log"] }
esp-hal-embassy = { version = "0.4.0", optional = true }

embassy-time = { version = "0.3.0", optional = true }
embassy-executor = { version = "0.6.0", package = "embassy-executor", features = [
Expand All @@ -42,9 +42,8 @@ embassy-net = { version = "0.4.0", features = [
], optional = true }


esp-wifi = { version = "0.9.1", features = [
esp-wifi = { version = "0.10.1", features = [
"phy-enable-usb",
"embedded-svc",
"wifi-default",
] }
smoltcp = { version = "0.11.0", default-features = false, features = [
Expand All @@ -70,10 +69,11 @@ esp-mbedtls = { path = "./esp-mbedtls" }
edge-http = { version = "0.3.0", optional = true }
edge-nal-embassy = { version = "0.3.0", optional = true }
cfg-if = "1.0.0"
esp-alloc = "0.5.0"

[[example]]
name = "crypto_self_test"
required-features = ["esp-wifi/wifi-logs"]
required-features = ["esp-wifi/sys-logs"]

[[example]]
name = "async_client"
Expand All @@ -98,27 +98,31 @@ required-features = ["async", "esp-hal-embassy", "edge-nal-embassy", "edge-http"
[features]
esp32 = [
"esp-hal/esp32",
"esp-hal-embassy?/esp32",
"esp-backtrace/esp32",
"esp-println/esp32",
"esp-wifi/esp32",
"esp-mbedtls/esp32",
]
esp32c3 = [
"esp-hal/esp32c3",
"esp-hal-embassy?/esp32c3",
"esp-backtrace/esp32c3",
"esp-println/esp32c3",
"esp-wifi/esp32c3",
"esp-mbedtls/esp32c3",
]
esp32s2 = [
"esp-hal/esp32s2",
"esp-hal-embassy?/esp32s2",
"esp-backtrace/esp32s2",
"esp-println/esp32s2",
"esp-wifi/esp32s2",
"esp-mbedtls/esp32s2",
]
esp32s3 = [
"esp-hal/esp32s3",
"esp-hal-embassy?/esp32s3",
"esp-backtrace/esp32s3",
"esp-println/esp32s3",
"esp-wifi/esp32s3",
Expand All @@ -132,5 +136,5 @@ async = [
"embassy-time",
"dep:embedded-io-async",
"esp-mbedtls/async",
"esp-hal/async",
"esp-hal-embassy"
]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ SSID=<your_ssid> PASSWORD=<your_password> cargo +esp run --release --example syn
RISC-V:

```shell
SSID=<your_ssid> PASSWORD=<your_password> cargo +nightly-2023-03-09 run --release --example async_client -F esp32c3,async --target riscv32imc-unknown-none-elf
SSID=<your_ssid> PASSWORD=<your_password> cargo +nightly run --release --example async_client -F esp32c3,async --target riscv32imc-unknown-none-elf
```

Here's a table of the architectures with their corresponding target for quick reference:

| Architecture | Target | Toolchain |
| ------------ | --------------------------- | ------------------ |
| esp32 | xtensa-esp32-none-elf | esp |
| esp32c3 | riscv32imc-unknown-none-elf | nightly-2023-03-09 |
| esp32c3 | riscv32imc-unknown-none-elf | nightly |
| esp32s3 | xtensa-esp32s3-none-elf | esp |

Heres's a list of all the examples with their description:
Expand Down
3 changes: 0 additions & 3 deletions cfg.toml

This file was deleted.

2 changes: 1 addition & 1 deletion esp-mbedtls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ log = "0.4.17"
embedded-io = { version = "0.6.1" }
embedded-io-async = { version = "0.6.0", optional = true }
crypto-bigint = { version = "0.5.3", default-features = false, features = ["extra-sizes"] }
esp-hal = { version = "0.20.1" }
esp-hal = { version = "0.21.0" }
cfg-if = "1.0.0"
edge-nal = { version = "0.3.0", optional = true }
edge-nal-embassy = { version = "0.3.0", optional = true }
Expand Down
28 changes: 14 additions & 14 deletions examples/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ use esp_wifi::wifi::{
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiStaDevice,
WifiState,
};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::{
clock::ClockControl, peripherals::Peripherals, rng::Rng, system::SystemControl,
timer::timg::TimerGroup,
};
use esp_wifi::{init, EspWifiInitFor};
use hal::{prelude::*, rng::Rng, timer::timg::TimerGroup};

// Patch until https://github.com/embassy-rs/static-cell/issues/16 is fixed
macro_rules! mk_static {
Expand All @@ -45,18 +42,21 @@ const PASSWORD: &str = env!("PASSWORD");
async fn main(spawner: Spawner) -> ! {
init_logger(log::LevelFilter::Info);

let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
});

esp_alloc::heap_allocator!(115 * 1024);

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timg0 = TimerGroup::new(peripherals.TIMG0);

let init = initialize(
let init = init(
EspWifiInitFor::Wifi,
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
&clocks,
)
.unwrap();

Expand All @@ -66,12 +66,12 @@ async fn main(spawner: Spawner) -> ! {

cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0);
let timg1 = TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timg1.timer0);
} else {
use esp_hal::timer::systimer::{SystemTimer, Target};
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
esp_hal_embassy::init(systimer.alarm0);
}
}

Expand Down
28 changes: 14 additions & 14 deletions examples/async_client_mTLS.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ use esp_wifi::wifi::{
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiStaDevice,
WifiState,
};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::{
clock::ClockControl, peripherals::Peripherals, rng::Rng, system::SystemControl,
timer::timg::TimerGroup,
};
use esp_wifi::{init, EspWifiInitFor};
use hal::{prelude::*, rng::Rng, timer::timg::TimerGroup};

// Patch until https://github.com/embassy-rs/static-cell/issues/16 is fixed
macro_rules! mk_static {
Expand All @@ -45,18 +42,21 @@ const PASSWORD: &str = env!("PASSWORD");
async fn main(spawner: Spawner) -> ! {
init_logger(log::LevelFilter::Info);

let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
});

esp_alloc::heap_allocator!(115 * 1024);

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timg0 = TimerGroup::new(peripherals.TIMG0);

let init = initialize(
let init = init(
EspWifiInitFor::Wifi,
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
&clocks,
)
.unwrap();

Expand All @@ -66,12 +66,12 @@ async fn main(spawner: Spawner) -> ! {

cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0);
let timg1 = TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timg1.timer0);
} else {
use esp_hal::timer::systimer::{SystemTimer, Target};
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
esp_hal_embassy::init(systimer.alarm0);
}
}

Expand Down
29 changes: 15 additions & 14 deletions examples/async_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use embassy_net::{Config, IpListenEndpoint, Stack, StackResources};

use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_alloc as _;
use esp_backtrace as _;
use esp_mbedtls::{asynch::Session, set_debug, Certificates, Mode, TlsVersion};
use esp_mbedtls::{TlsError, X509};
Expand All @@ -25,11 +26,8 @@ use esp_wifi::wifi::{
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiStaDevice,
WifiState,
};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::{
clock::ClockControl, peripherals::Peripherals, rng::Rng, system::SystemControl,
timer::timg::TimerGroup,
};
use esp_wifi::{init, EspWifiInitFor};
use hal::{prelude::*, rng::Rng, timer::timg::TimerGroup};

// Patch until https://github.com/embassy-rs/static-cell/issues/16 is fixed
macro_rules! mk_static {
Expand All @@ -48,18 +46,21 @@ const PASSWORD: &str = env!("PASSWORD");
async fn main(spawner: Spawner) -> ! {
init_logger(log::LevelFilter::Info);

let mut peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let mut peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
});

esp_alloc::heap_allocator!(115 * 1024);

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timg0 = TimerGroup::new(peripherals.TIMG0);

let init = initialize(
let init = init(
EspWifiInitFor::Wifi,
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
&clocks,
)
.unwrap();

Expand All @@ -69,12 +70,12 @@ async fn main(spawner: Spawner) -> ! {

cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0);
let timg1 = TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timg1.timer0);
} else {
use esp_hal::timer::systimer::{SystemTimer, Target};
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
esp_hal_embassy::init(systimer.alarm0);
}
}

Expand Down
28 changes: 14 additions & 14 deletions examples/async_server_mTLS.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ use esp_wifi::wifi::{
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiStaDevice,
WifiState,
};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::{
clock::ClockControl, peripherals::Peripherals, rng::Rng, system::SystemControl,
timer::timg::TimerGroup,
};
use esp_wifi::{init, EspWifiInitFor};
use hal::{prelude::*, rng::Rng, timer::timg::TimerGroup};

// Patch until https://github.com/embassy-rs/static-cell/issues/16 is fixed
macro_rules! mk_static {
Expand All @@ -65,18 +62,21 @@ const PASSWORD: &str = env!("PASSWORD");
async fn main(spawner: Spawner) -> ! {
init_logger(log::LevelFilter::Info);

let mut peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let mut peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
});

esp_alloc::heap_allocator!(115 * 1024);

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timg0 = TimerGroup::new(peripherals.TIMG0);

let init = initialize(
let init = init(
EspWifiInitFor::Wifi,
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
&clocks,
)
.unwrap();

Expand All @@ -86,12 +86,12 @@ async fn main(spawner: Spawner) -> ! {

cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0);
let timg1 = TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timg1.timer0);
} else {
use esp_hal::timer::systimer::{SystemTimer, Target};
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
esp_hal_embassy::init(systimer.alarm0);
}
}

Expand Down
Loading

0 comments on commit e6e698f

Please sign in to comment.