diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 0504ab7a1f0..eccd0a25a56 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -247,11 +247,16 @@ def _validate(config): f"{config[CONF_TYPE]} PHY requires RMII interface and is only supported " f"on ESP32 classic and ESP32-P4, not {variant}" ) - elif CORE.is_rp2040 and config[CONF_TYPE] not in RP2040_SPI_ETHERNET_TYPES: - raise cv.Invalid( - f"Only {', '.join(RP2040_SPI_ETHERNET_TYPES)} are supported on RP2040, " - f"not {config[CONF_TYPE]}" - ) + elif CORE.is_rp2040: + if config[CONF_TYPE] not in RP2040_SPI_ETHERNET_TYPES: + raise cv.Invalid( + f"Only {', '.join(RP2040_SPI_ETHERNET_TYPES)} are supported on RP2040, " + f"not {config[CONF_TYPE]}" + ) + if CONF_CLOCK_SPEED in config: + raise cv.Invalid(f"'{CONF_CLOCK_SPEED}' is not supported on RP2040") + if CONF_POLLING_INTERVAL in config: + raise cv.Invalid(f"'{CONF_POLLING_INTERVAL}' is not supported on RP2040") return config diff --git a/esphome/components/ethernet/ethernet_component_rp2040.cpp b/esphome/components/ethernet/ethernet_component_rp2040.cpp index 8fe930bdbf4..22a748ef48a 100644 --- a/esphome/components/ethernet/ethernet_component_rp2040.cpp +++ b/esphome/components/ethernet/ethernet_component_rp2040.cpp @@ -62,6 +62,8 @@ void EthernetComponent::setup() { if (!success) { ESP_LOGE(TAG, "Failed to initialize W5500 Ethernet"); + delete this->eth_; // NOLINT(cppcoreguidelines-owning-memory) + this->eth_ = nullptr; this->mark_failed(); return; } @@ -178,6 +180,7 @@ network::IPAddresses EthernetComponent::get_ip_addresses() { } network::IPAddress EthernetComponent::get_dns_address(uint8_t num) { + LwIPLock lock; const ip_addr_t *dns_ip = dns_getserver(num); return dns_ip; } @@ -234,6 +237,7 @@ void EthernetComponent::start_connect_() { if (this->manual_ip_.has_value()) { // Static IP was already configured before begin() in setup() // Set DNS servers + LwIPLock lock; if (this->manual_ip_->dns1.is_set()) { ip_addr_t d; d = this->manual_ip_->dns1; @@ -269,19 +273,25 @@ void EthernetComponent::dump_connect_params_() { char mac_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE]; auto *netif = this->eth_->getNetIf(); - ESP_LOGCONFIG( - TAG, - " IP Address: %s\n" - " Hostname: '%s'\n" - " Subnet: %s\n" - " Gateway: %s\n" - " DNS1: %s\n" - " DNS2: %s\n" - " MAC Address: %s", - network::IPAddress(&netif->ip_addr).str_to(ip_buf), App.get_name().c_str(), - network::IPAddress(&netif->netmask).str_to(subnet_buf), network::IPAddress(&netif->gw).str_to(gateway_buf), - network::IPAddress(dns_getserver(0)).str_to(dns1_buf), network::IPAddress(dns_getserver(1)).str_to(dns2_buf), - this->get_eth_mac_address_pretty_into_buffer(mac_buf)); + const ip_addr_t *dns_ip1; + const ip_addr_t *dns_ip2; + { + LwIPLock lock; + dns_ip1 = dns_getserver(0); + dns_ip2 = dns_getserver(1); + } + ESP_LOGCONFIG(TAG, + " IP Address: %s\n" + " Hostname: '%s'\n" + " Subnet: %s\n" + " Gateway: %s\n" + " DNS1: %s\n" + " DNS2: %s\n" + " MAC Address: %s", + network::IPAddress(&netif->ip_addr).str_to(ip_buf), App.get_name().c_str(), + network::IPAddress(&netif->netmask).str_to(subnet_buf), + network::IPAddress(&netif->gw).str_to(gateway_buf), network::IPAddress(dns_ip1).str_to(dns1_buf), + network::IPAddress(dns_ip2).str_to(dns2_buf), this->get_eth_mac_address_pretty_into_buffer(mac_buf)); } void EthernetComponent::set_clk_pin(uint8_t clk_pin) { this->clk_pin_ = clk_pin; }