From 95ba24bef337cff550348477ed1ad609a1004e45 Mon Sep 17 00:00:00 2001 From: Thomas Schaller Date: Thu, 31 Aug 2023 17:44:18 +0200 Subject: [PATCH] Add example for ethernet (#289) * Add example for ethernet * Make eth example esp32 only * Change sys imports * Try just importing esp_idf_svc --- examples/eth.rs | 65 +++++++++++++++++++++++++++++++++ examples/http_request.rs | 1 + examples/nvs_get_set_c_style.rs | 1 + examples/tls.rs | 1 + examples/wifi.rs | 1 + examples/wifi_async.rs | 1 + 6 files changed, 70 insertions(+) create mode 100644 examples/eth.rs diff --git a/examples/eth.rs b/examples/eth.rs new file mode 100644 index 00000000000..4fcfad5c45e --- /dev/null +++ b/examples/eth.rs @@ -0,0 +1,65 @@ +#[cfg(esp32)] +use esp_idf_svc::{ + eth::{BlockingEth, EspEth, EthDriver}, + eventloop::EspSystemEventLoop, + hal::{gpio, prelude::Peripherals}, + log::EspLogger, +}; +#[cfg(esp32)] +use log::info; + +#[cfg(esp32)] +fn main() -> anyhow::Result<()> { + esp_idf_svc::sys::link_patches(); + EspLogger::initialize_default(); + + let peripherals = Peripherals::take().unwrap(); + let pins = peripherals.pins; + let sys_loop = EspSystemEventLoop::take()?; + + // Make sure to configure ethernet in sdkconfig and adjust the parameters below for your hardware + let eth_driver = EthDriver::new( + peripherals.mac, + pins.gpio25, + pins.gpio26, + pins.gpio27, + pins.gpio23, + pins.gpio22, + pins.gpio21, + pins.gpio19, + pins.gpio18, + esp_idf_svc::eth::RmiiClockConfig::::OutputInvertedGpio17( + pins.gpio17, + ), + Some(pins.gpio5), + esp_idf_svc::eth::RmiiEthChipset::LAN87XX, + Some(0), + sys_loop.clone(), + )?; + let eth = EspEth::wrap(eth_driver)?; + + info!("Eth created"); + + let mut eth = BlockingEth::wrap(eth, sys_loop.clone())?; + + info!("Starting eth..."); + + eth.start()?; + + info!("Waiting for DHCP lease..."); + + eth.wait_netif_up()?; + + let ip_info = eth.eth().netif().get_ip_info()?; + + info!("Eth DHCP info: {:?}", ip_info); + + Ok(()) +} + +#[cfg(not(esp32))] +fn main() { + use esp_idf_svc::{self as _}; + + panic!("This example is configured for esp32, please adjust pins to your module"); +} diff --git a/examples/http_request.rs b/examples/http_request.rs index d029567db42..0c72549ba1b 100644 --- a/examples/http_request.rs +++ b/examples/http_request.rs @@ -19,6 +19,7 @@ const SSID: &str = env!("WIFI_SSID"); const PASSWORD: &str = env!("WIFI_PASS"); fn main() -> anyhow::Result<()> { + esp_idf_svc::sys::link_patches(); EspLogger::initialize_default(); // Setup Wifi diff --git a/examples/nvs_get_set_c_style.rs b/examples/nvs_get_set_c_style.rs index e992d89e1f1..18345078c96 100644 --- a/examples/nvs_get_set_c_style.rs +++ b/examples/nvs_get_set_c_style.rs @@ -14,6 +14,7 @@ use esp_idf_svc::nvs::*; use log::info; fn main() -> anyhow::Result<()> { + esp_idf_svc::sys::link_patches(); EspLogger::initialize_default(); let nvs_default_partition: EspNvsPartition = diff --git a/examples/tls.rs b/examples/tls.rs index 1e59c8d5f00..5bd3a825691 100644 --- a/examples/tls.rs +++ b/examples/tls.rs @@ -50,6 +50,7 @@ A7sKPPcw7+uvTPyLNhBzPvOk -----END CERTIFICATE-----\0"; fn main() -> anyhow::Result<()> { + esp_idf_svc::sys::link_patches(); EspLogger::initialize_default(); let peripherals = Peripherals::take().unwrap(); diff --git a/examples/wifi.rs b/examples/wifi.rs index 2128cc7ce76..a56ce15d656 100644 --- a/examples/wifi.rs +++ b/examples/wifi.rs @@ -15,6 +15,7 @@ const SSID: &str = env!("WIFI_SSID"); const PASSWORD: &str = env!("WIFI_PASS"); fn main() -> anyhow::Result<()> { + esp_idf_svc::sys::link_patches(); EspLogger::initialize_default(); let peripherals = Peripherals::take().unwrap(); diff --git a/examples/wifi_async.rs b/examples/wifi_async.rs index 334c052e072..bb90dee540d 100644 --- a/examples/wifi_async.rs +++ b/examples/wifi_async.rs @@ -18,6 +18,7 @@ const SSID: &str = env!("WIFI_SSID"); const PASSWORD: &str = env!("WIFI_PASS"); fn main() -> anyhow::Result<()> { + esp_idf_svc::sys::link_patches(); EspLogger::initialize_default(); let peripherals = Peripherals::take().unwrap();