Skip to content
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
14 changes: 7 additions & 7 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ target = "riscv32imc-esp-espidf"
[target.xtensa-esp32-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = ["--cfg", "mio_unsupported_force_poll_poll", "--cfg", "espidf_time64", "-C", "default-linker-libraries"]
rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[target.xtensa-esp32s2-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = ["--cfg", "mio_unsupported_force_poll_poll", "--cfg", "espidf_time64", "-C", "default-linker-libraries"]
rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[target.xtensa-esp32s3-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = ["--cfg", "mio_unsupported_force_poll_poll", "--cfg", "espidf_time64", "-C", "default-linker-libraries"]
rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[target.riscv32imc-esp-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = ["--cfg", "mio_unsupported_force_poll_poll", "--cfg", "espidf_time64", "-C", "default-linker-libraries"]
rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[target.riscv32imac-esp-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = ["--cfg", "mio_unsupported_force_poll_poll", "--cfg", "espidf_time64", "-C", "default-linker-libraries"]
rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[unstable]
build-std = ["std", "panic_abort"]

[env]
ESP_IDF_VERSION = "release/v5.0"
CROSS_COMPILE = { value = ".embuild/espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/riscv32-esp-elf", relative = true }
ESP_IDF_VERSION = "v5.4.2"
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
19 changes: 6 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@ opt-level = "s"
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[patch.crates-io]
tokio = { git = "https://github.com/tokio-rs/tokio", branch = "master" }
mio = { git = "https://github.com/tokio-rs/mio", branch = "master" }
socket2 = { git = "https://github.com/rust-lang/socket2", branch = "master" }

[dependencies]
esp-idf-sys = { version = "0.33.1", features = ["binstart"] }
esp-idf-svc = { version = "0.46.0", features = ["experimental"] }
esp-idf-hal = "0.41.2"
embedded-svc = { version = "0.25.3", features = ["experimental"] }
embedded-hal = "0.2.7"
log = "0.4.17"
esp-idf-sys = { version = "0.36.1", features = ["binstart"] }
esp-idf-svc = { version = "0.51.0"}
esp-idf-hal = "0.45.2"
embedded-svc = { version = "0.28.1"}
log = "0.4.27"
anyhow = "1"
tokio = { version = "*", features = ["rt", "net", "io-util"] }
mio = { version = "0.8.8", features = ["log"] }

[build-dependencies]
embuild = "0.31.0"
embuild = "0.33.0"
anyhow = "1"
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ hello

You may optionally use `cargo run --target xtensa-esp32-espidf` or any of the other supported targets which should work provided that you followed the [esp-rs](https://github.com/esp-rs) installation instructions above.

## Future work

esp32 support still requires the experimental `mio_unsupported_force_poll_poll` feature. To mature this support, we'll need to address a few more uptsream issues:

- [ ] https://github.com/tokio-rs/mio/issues/1703
- [ ] https://github.com/tokio-rs/tokio/issues/5866

## Alternatives

To use async on esp32, you can also use a number of other executors and reactor combos, including smol and async-task. ~~Upstream esp-rs support appears to be leaning toward [edge-executor](https://github.com/ivmarkov/edge-executor) which can be utilized to support ISR-based wakeups and other useful embedded features that tokio lacks. See https://github.com/ivmarkov/rust-esp32-std-demo/issues/153#issuecomment-1633598784 for discussion of some of the advantages with this approach.~~ Upstream esp-rs is moving toward [support for all executors](https://github.com/esp-rs/esp-idf-hal/pull/315) generically, including tokio!
Expand Down
5 changes: 2 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
fn main() -> anyhow::Result<()> {
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
embuild::build::LinkArgs::output_propagated("ESP_IDF")
embuild::espidf::sysenv::output();
Ok(())
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "esp"
4 changes: 2 additions & 2 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set to VERBOSE to debug issues if things aren't working properly... for your
# application you probably want INFO.
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y
#CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y
#CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y

# The tokio runtime and typical programs built with it need quite a bit of
# stack space, but the good news is that you don't need many pthreads for
Expand Down
15 changes: 6 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use esp_idf_svc::nvs::EspDefaultNvsPartition;
use esp_idf_svc::timer::EspTaskTimerService;
use esp_idf_svc::wifi::{AsyncWifi, EspWifi};
use esp_idf_sys as _;
use esp_idf_sys::{esp, esp_app_desc, EspError};
use esp_idf_sys::{esp, EspError};
use log::info;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
Expand All @@ -18,8 +18,6 @@ const WIFI_PASS: &str = "password";
// a machine on the same Wi-Fi network.
const TCP_LISTENING_PORT: u16 = 12345;

esp_app_desc!();

fn main() -> anyhow::Result<()> {
esp_idf_sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
Expand Down Expand Up @@ -72,8 +70,8 @@ impl<'a> WifiLoop<'a> {
pub async fn configure(&mut self) -> Result<(), EspError> {
info!("Setting Wi-Fi credentials...");
self.wifi.set_configuration(&Configuration::Client(ClientConfiguration {
ssid: WIFI_SSID.into(),
password: WIFI_PASS.into(),
ssid: WIFI_SSID.try_into().unwrap(),
password: WIFI_PASS.try_into().unwrap(),
..Default::default()
}))?;

Expand All @@ -93,20 +91,19 @@ impl<'a> WifiLoop<'a> {
&mut self,
exit_after_first_connect: bool,
) -> Result<(), EspError> {
let wifi = &mut self.wifi;
loop {
// Wait for disconnect before trying to connect again. This loop ensures
// we stay connected and is commonly missing from trivial examples as it's
// way too difficult to showcase the core logic of an example and have
// a proper Wi-Fi event loop without a robust async runtime. Fortunately, we can do it
// now!
wifi.wifi_wait(|| wifi.is_up(), None).await?;
self.wifi.wifi_wait(|wifi| wifi.is_up(), None).await?;

info!("Connecting to Wi-Fi...");
wifi.connect().await?;
self.wifi.connect().await?;

info!("Waiting for association...");
wifi.ip_wait_while(|| wifi.is_up().map(|s| !s), None).await?;
self.wifi.ip_wait_while(|wifi| wifi.is_up().map(|s| !s), None).await?;

if exit_after_first_connect {
return Ok(());
Expand Down