Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 2024-04-26 #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ rustflags = ["--cfg", "mio_unsupported_force_poll_poll", "--cfg", "espidf_time64
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.1.3"
21 changes: 13 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ 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"] }
esp-idf-svc = { version = "0.48", default-features = false }
embedded-svc = "*"
embedded-hal = "0.2.7"
log = "0.4.17"
anyhow = "1"
tokio = { version = "*", features = ["rt", "net", "io-util"] }
mio = { version = "0.8.8", features = ["log"] }
mio = { version = "0.8.11", features = ["log"] }

[features]
default = ["std", "embassy", "esp-idf-svc/native"]
pio = ["esp-idf-svc/pio"]
std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"]
alloc = ["esp-idf-svc/alloc"]
nightly = ["esp-idf-svc/nightly"]
experimental = ["esp-idf-svc/experimental"]
embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"]

[build-dependencies]
embuild = "0.31.0"
embuild = "0.31.4"
anyhow = "1"
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")
fn main() {
embuild::espidf::sysenv::output();
}
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
35 changes: 18 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use embedded_svc::wifi::{ClientConfiguration, Configuration};
use esp_idf_hal::prelude::Peripherals;
use esp_idf_svc::hal::prelude::Peripherals;
use esp_idf_svc::eventloop::EspSystemEventLoop;
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_svc::wifi::{AsyncWifi, EspWifi, AuthMethod, ClientConfiguration, Configuration};
use esp_idf_svc::sys::{esp, EspError};
use log::info;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
Expand All @@ -18,20 +16,20 @@ 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();
// It is necessary to call this function once. Otherwise, some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();

// eventfd is needed by our mio poll implementation. Note you should set max_fds
// higher if you have other code that may need eventfd.
info!("Setting up eventfd...");
let config = esp_idf_sys::esp_vfs_eventfd_config_t {
max_fds: 1,
let config = esp_idf_svc::sys::esp_vfs_eventfd_config_t {
max_fds: 5,
..Default::default()
};
esp! { unsafe { esp_idf_sys::esp_vfs_eventfd_register(&config) } }?;
esp! { unsafe { esp_idf_svc::sys::esp_vfs_eventfd_register(&config) } }?;

info!("Setting up board...");
let peripherals = Peripherals::take().unwrap();
Expand Down Expand Up @@ -71,11 +69,14 @@ pub struct WifiLoop<'a> {
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(),
let wifi_configuration: Configuration = Configuration::Client(ClientConfiguration {
ssid: WIFI_SSID.parse().unwrap(),
password: WIFI_PASS.parse().unwrap(),
auth_method: AuthMethod::WPA2Personal,
channel: None,
..Default::default()
}))?;
});
self.wifi.set_configuration(&wifi_configuration)?;

info!("Starting Wi-Fi driver...");
self.wifi.start().await
Expand All @@ -100,13 +101,13 @@ impl<'a> WifiLoop<'a> {
// 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?;
wifi.wifi_wait(|this| this.is_up(), None).await?;

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

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

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