Skip to content

Commit

Permalink
Update esp-hal, esp-wifi, esp-idf and edge-net dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Jan 5, 2025
1 parent 1431835 commit 773dba3
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 293 deletions.
4 changes: 0 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ runner = "espflash flash --monitor --baud 921600"
rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Trom_functions.x",
]

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

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

# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code
Expand All @@ -39,7 +37,6 @@ runner = "espflash flash --monitor --baud 921600"
rustflags = [
#"-C", "linker=rust-lld",
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",
]

[target.xtensa-esp32s3-none-elf]
Expand All @@ -48,7 +45,6 @@ runner = "espflash flash --monitor --baud 921600"
rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Trom_functions.x",
]

[target.'cfg(target_os = "espidf")']
Expand Down
52 changes: 24 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,40 @@ opt-level = "z"
opt-level = 3

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

embassy-time = { version = "0.3.0", optional = true }
embassy-executor = { version = "=0.6.0", package = "embassy-executor", features = [
embassy-executor = { version = "0.6", package = "embassy-executor", features = [
"nightly",
"integrated-timers",
], optional = true }
embassy-net = { version = "0.4.0", features = [
embassy-net = { version = "0.5.0", features = [
"tcp",
"udp",
"dhcpv4",
"medium-ethernet",
], optional = true }

esp-wifi = { version = "0.10.1", optional = true, features = ["phy-enable-usb", "wifi-default", "sys-logs"] }
smoltcp = { version = "0.11.0", optional = true, default-features = false, features = [
"proto-igmp",
esp-wifi = { version = "0.11.0", optional = true, features = ["sys-logs", "utils", "wifi"] }
blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack", rev = "1c581661d78e0cf0f17b936297179b993fb149d7" }
smoltcp11 = { package = "smoltcp", version = "0.11.0", optional = true, default-features = false, features = [
"proto-ipv4",
"socket-tcp",
"socket-icmp",
"socket-udp",
"medium-ethernet",
"proto-dhcpv4",
"socket-raw",
"socket-dhcpv4",
] }
smoltcp = { version = "0.12.0", optional = true, default-features = false, features = [
"proto-ipv4",
"socket-tcp",
"socket-icmp",
Expand All @@ -66,15 +76,15 @@ static_cell = { version = "2.1", features = ["nightly"] }

esp-mbedtls = { path = "./esp-mbedtls" }

edge-http = { version = "0.3.0", optional = true }
edge-nal = { version = "0.3.0", optional = true }
edge-nal-embassy = { version = "0.3.0", optional = true }
edge-http = { version = "0.4.0", optional = true }
edge-nal = { version = "0.4.0", optional = true }
edge-nal-embassy = { version = "0.4.0", optional = true }
cfg-if = "1.0.0"
esp-alloc = { version = "0.5.0", optional = true}
enumset = { version = "1", default-features = false }

[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-svc = { version = "0.49.1", features = ["binstart"] }
esp-idf-svc = { version = "0.50", features = ["binstart"] }

[[example]]
name = "crypto_self_test"
Expand Down Expand Up @@ -104,8 +114,8 @@ name = "edge_server"
required-features = ["examples-async", "edge-http"]

[features]
examples = ["esp-hal", "esp-backtrace", "esp-println", "esp-wifi", "smoltcp", "esp-alloc"]
examples-async = ["examples", "esp-hal-embassy", "embassy-time", "embassy-executor", "embassy-net", "edge-http", "edge-nal", "edge-nal-embassy", "esp-wifi/async", "esp-wifi/embassy-net", "esp-mbedtls/async", "esp-mbedtls/edge-nal"]
examples = ["esp-hal", "esp-backtrace", "esp-println", "esp-wifi", "smoltcp", "smoltcp11", "esp-alloc"]
examples-async = ["examples", "esp-hal-embassy", "embassy-time", "embassy-executor", "embassy-net", "edge-http", "edge-nal", "edge-nal-embassy", "esp-mbedtls/async", "esp-mbedtls/edge-nal"]
examples-std = ["critical-section/std"]

esp32 = [
Expand Down Expand Up @@ -142,18 +152,4 @@ esp32s3 = [
]

[build-dependencies]
embuild = { version = "0.32", features = ["espidf"] }

# Patch until new release
[patch.crates-io]
edge-http = { git = "https://github.com/ivmarkov/edge-net" }
edge-nal = { git = "https://github.com/ivmarkov/edge-net" }
edge-nal-embassy = { git = "https://github.com/ivmarkov/edge-net" }
esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc" }
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }

# Patch before 0.6.0 got yanked
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
embuild = { version = "0.33", features = ["espidf"] }
8 changes: 4 additions & 4 deletions esp-mbedtls-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ rust-version = "1.82"

[build-dependencies]
anyhow = "1.0.68"
bindgen = "0.68.1"
bindgen = "0.71.1"
env_logger = "0.10.0"
log = "0.4.17"
cmake = "0.1.52"
fs_extra = "1.3.0"
embuild = "0.32"
embuild = "0.33"

[dependencies]
# For malloc/free
# TODO: Replace with `esp-alloc` once `esp-alloc` starts to provide `malloc` and `free` in future
# ... or switch to our own `mbedtls_malloc/free`
esp-wifi = { version = "0.10.1", default-features = false, optional = true }
esp-wifi = { version = "0.11.0", default-features = false, optional = true }

# ESP-IDF: The mbedtls lib distributed with ESP-IDF is used
[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-sys = { version = "0.35", default-features = false }
esp-idf-sys = { version = "0.36", default-features = false }

# All other platforms: mbedtls libs and bindings are created on the fly

Expand Down
6 changes: 3 additions & 3 deletions esp-mbedtls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ log = { version = "0.4.17", default-features = false }
enumset = { version = "1", default-features = false }
embedded-io = { version = "0.6.1" }
embedded-io-async = { version = "0.6.0", optional = true }
esp-hal = { version = "0.21.0", optional = true }
esp-hal = { version = "0.22.0", optional = true }
# For malloc/free
# TODO: Replace with `esp-alloc` once `esp-alloc` starts to provide `malloc` and `free` in future
# ... or switch to our own `mbedtls_malloc/free`
esp-wifi = { version = "0.10.1", default-features = false, optional = true }
esp-wifi = { version = "0.11.0", default-features = false, optional = true }
cfg-if = "1.0.0"
edge-nal = { version = "0.3.0", optional = true }
edge-nal = { version = "0.4.0", optional = true }
critical-section = "1.1.3"
crypto-bigint = { version = "0.5.3", optional = true, default-features = false, features = ["extra-sizes"] }

Expand Down
17 changes: 17 additions & 0 deletions esp-mbedtls/src/edge_nal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ where
}
}

impl<T> edge_nal::TcpSplit for Session<'_, T>
where
T: edge_nal::TcpSplit + embedded_io_async::Read + embedded_io_async::Write + edge_nal::Readable,
{
type Read<'a> = Self
where
Self: 'a;

type Write<'a> = Self
where
Self: 'a;

fn split(&mut self) -> (Self::Read<'_>, Self::Write<'_>) {
panic!("Splitting a TLS session is not supported yet");
}
}

impl<T> edge_nal::TcpShutdown for Session<'_, T>
where
T: embedded_io_async::Read + embedded_io_async::Write + edge_nal::TcpShutdown,
Expand Down
65 changes: 33 additions & 32 deletions examples/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
pub use esp_hal as hal;

use embassy_net::tcp::TcpSocket;
use embassy_net::{Config, Ipv4Address, Stack, StackResources};
use embassy_net::{Config, Ipv4Address, Runner, StackResources};

use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
Expand All @@ -22,7 +22,7 @@ use esp_wifi::wifi::{
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiStaDevice,
WifiState,
};
use esp_wifi::{init, EspWifiInitFor};
use esp_wifi::{init, EspWifiController};
use hal::{prelude::*, rng::Rng, timer::timg::TimerGroup};

// Patch until https://github.com/embassy-rs/static-cell/issues/16 is fixed
Expand Down Expand Up @@ -52,17 +52,19 @@ async fn main(spawner: Spawner) -> ! {

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

let init = init(
EspWifiInitFor::Wifi,
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
)
.unwrap();
let init = &*mk_static!(
EspWifiController<'_>,
init(
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
)
.unwrap()
);

let wifi = peripherals.WIFI;
let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap();
esp_wifi::wifi::new_with_mode(init, wifi, WifiStaDevice).unwrap();

cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
Expand All @@ -80,18 +82,17 @@ async fn main(spawner: Spawner) -> ! {
let seed = 1234; // very random, very secure seed

// Init network stack
let stack = &*mk_static!(
Stack<WifiDevice<'_, WifiStaDevice>>,
Stack::new(
wifi_interface,
config,
mk_static!(StackResources<3>, StackResources::<3>::new()),
seed
)
let (stack, runner) = embassy_net::new(
wifi_interface,
config,
mk_static!(StackResources<3>, StackResources::<3>::new()),
seed,
);

let runner = mk_static!(Runner<'_, WifiDevice<'static, WifiStaDevice>>, runner);

spawner.spawn(connection(controller)).ok();
spawner.spawn(net_task(&stack)).ok();
spawner.spawn(net_task(runner)).ok();

let mut rx_buffer = [0; 4096];
let mut tx_buffer = [0; 4096];
Expand All @@ -112,7 +113,7 @@ async fn main(spawner: Spawner) -> ! {
Timer::after(Duration::from_millis(500)).await;
}

let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer);
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);

socket.set_timeout(Some(Duration::from_secs(10)));

Expand All @@ -121,6 +122,7 @@ async fn main(spawner: Spawner) -> ! {
let r = socket.connect(remote_endpoint).await;
if let Err(e) = r {
println!("connect error: {:?}", e);
#[allow(clippy::empty_loop)]
loop {}
}

Expand Down Expand Up @@ -160,6 +162,7 @@ async fn main(spawner: Spawner) -> ! {
.await;
if let Err(e) = r {
println!("write error: {:?}", e);
#[allow(clippy::empty_loop)]
loop {}
}

Expand All @@ -179,21 +182,19 @@ async fn main(spawner: Spawner) -> ! {
println!();
println!("Done");

#[allow(clippy::empty_loop)]
loop {}
}

#[embassy_executor::task]
async fn connection(mut controller: WifiController<'static>) {
println!("start connection task");
println!("Device capabilities: {:?}", controller.get_capabilities());
println!("Device capabilities: {:?}", controller.capabilities());
loop {
match esp_wifi::wifi::get_wifi_state() {
WifiState::StaConnected => {
// wait until we're no longer connected
controller.wait_for_event(WifiEvent::StaDisconnected).await;
Timer::after(Duration::from_millis(5000)).await
}
_ => {}
if matches!(esp_wifi::wifi::wifi_state(), WifiState::StaConnected) {
// wait until we're no longer connected
controller.wait_for_event(WifiEvent::StaDisconnected).await;
Timer::after(Duration::from_millis(5000)).await
}
if !matches!(controller.is_started(), Ok(true)) {
let client_config = Configuration::Client(ClientConfiguration {
Expand All @@ -203,12 +204,12 @@ async fn connection(mut controller: WifiController<'static>) {
});
controller.set_configuration(&client_config).unwrap();
println!("Starting wifi");
controller.start().await.unwrap();
controller.start_async().await.unwrap();
println!("Wifi started!");
}
println!("About to connect...");

match controller.connect().await {
match controller.connect_async().await {
Ok(_) => println!("Wifi connected!"),
Err(e) => {
println!("Failed to connect to wifi: {e:?}");
Expand All @@ -219,6 +220,6 @@ async fn connection(mut controller: WifiController<'static>) {
}

#[embassy_executor::task]
async fn net_task(stack: &'static Stack<WifiDevice<'static, WifiStaDevice>>) {
stack.run().await
async fn net_task(runner: &'static mut Runner<'static, WifiDevice<'static, WifiStaDevice>>) {
runner.run().await
}
Loading

0 comments on commit 773dba3

Please sign in to comment.