-
Notifications
You must be signed in to change notification settings - Fork 183
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
Can't acquire static IP when using W5500 ethernet chip #492
Comments
|
Thanks! Removing the For information, the dependencies in this test project are:
|
I think that might explain it.... We don't receive the I suggest we keep this open, as ideally - the "wait" should work even for static IP addresses. |
In svc "0.49" we still have this buggy code. In other words, we might be waiting on the wrong event ID. In latest Perhaps you can try |
After patching esp-idf-sys, esp-idf-hal and esp-idf-svc to master and making a small change to make the code build (see full main.rs and Cargo.toml below), it looks like the situation is the same: Removing the call to Cargo.toml[package]
name = "esp-static-eth"
version = "0.1.0"
authors = ["Romain Deterre <[email protected]>"]
edition = "2021"
resolver = "2"
rust-version = "1.77"
[[bin]]
name = "esp-static-eth"
harness = false # do not use the built in cargo test harness -> resolve rust-analyzer errors
[profile.release]
opt-level = "s"
[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[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"]
[dependencies]
log = { version = "0.4", default-features = false }
esp-idf-svc = { version = "0.49", default-features = false }
anyhow = "1.0.89"
esp-idf-hal = "0.44.1"
heapless = "0.8.0"
[build-dependencies]
embuild = "0.32.0"
[patch.crates-io]
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }
esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc" } main.rsuse std::net::Ipv4Addr;
use std::str::FromStr;
use esp_idf_hal::gpio::AnyOutputPin;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::spi;
use esp_idf_hal::spi::config::DriverConfig;
use esp_idf_svc::eth::{BlockingEth, EspEth, EthDriver, SpiEth, SpiEthChipset};
use esp_idf_svc::eventloop::EspSystemEventLoop;
use esp_idf_svc::ipv4::{
ClientConfiguration as IpClientConfiguration, ClientSettings as IpClientSettings,
Configuration as IpConfiguration, Mask, Subnet, DHCPClientSettings
};
use esp_idf_svc::netif::{EspNetif, NetifConfiguration};
// Expects IPv4 address
const DEVICE_IP: Option<&str> = option_env!("DEVICE_IP");
// Expects IPv4 address
const GATEWAY_IP: Option<&str> = option_env!("GATEWAY_IP");
// Expects a number between 0 and 32, defaults to 24
const GATEWAY_NETMASK: Option<&str> = option_env!("GATEWAY_NETMASK");
fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
let peripherals = Peripherals::take()?;
let pins = peripherals.pins;
let sys_loop = EspSystemEventLoop::take()?;
let spi_driver = spi::SpiDriver::new(
peripherals.spi3,
pins.gpio27,
pins.gpio21,
Some(pins.gpio22),
&DriverConfig {
dma: spi::Dma::Auto(4096),
..Default::default()
},
)?;
let mut eth_driver = EthDriver::new_spi(
spi_driver,
pins.gpio23,
Some(pins.gpio26),
None::<AnyOutputPin>,
SpiEthChipset::W5500,
esp_idf_hal::units::Hertz(20 * 1000 * 1000),
Some(&[0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED]),
None,
sys_loop.clone(),
)?;
let netmask = GATEWAY_NETMASK.unwrap_or("24");
let netmask = u8::from_str(netmask)?;
let gateway_addr = Ipv4Addr::from_str(GATEWAY_IP.unwrap())?;
let static_ip = Ipv4Addr::from_str(DEVICE_IP.unwrap())?;
log::info!("Using static IP {}", DEVICE_IP.unwrap());
let ip_client_configuration = IpClientConfiguration::Fixed(IpClientSettings {
ip: static_ip,
subnet: Subnet {
gateway: gateway_addr,
mask: Mask(netmask),
},
// Can also be set to Ipv4Addrs if you need DNS
dns: None,
secondary_dns: None,
});
// log::info!("Using DHCP");
// let ip_client_configuration = IpClientConfiguration::DHCP(DHCPClientSettings {
// hostname: Some(
// heapless::String::try_from("croquette")
// .map_err(|_| anyhow!("Could not create static string"))?,
// ),
// });
eth_driver.start()?;
log::info!("EspEth");
let eth = EspEth::wrap_all(
eth_driver,
EspNetif::new_with_conf(&NetifConfiguration {
ip_configuration: Some(IpConfiguration::Client(ip_client_configuration)),
..NetifConfiguration::eth_default_client()
})?,
)?;
log::info!("BlockingEth");
let mut eth = BlockingEth::wrap(eth, sys_loop)?;
eth.start()?;
log::info!("Waiting for up...");
eth.wait_netif_up()?;
let ip_info = eth.eth().netif().get_ip_info()?;
log::info!(
"Eth info: {} {} {:?}",
eth.is_started()?,
eth.is_up()?,
ip_info
);
core::mem::forget(eth);
Ok(())
} |
Hello,
I'm running into an issue where configuring a static IP for a W5500 SPI ethernet chip does not work, but using DHCP works fine.
To test, I am using a recently generated
esp-rs/esp-idf-template
project with the code below, adapted from the wifi_static_ip.rs example in this repo.main.rs
The application stalls after printing "Waiting for up..." for about ten seconds and then terminates. Here is the output log:
Output log
I have also tested the static_ip example from esp-idf on the same hardware and the module manages to establish a connection without any issues.
The text was updated successfully, but these errors were encountered: