diff --git a/environments.ini b/environments.ini index 48aa8db..d6b1a20 100644 --- a/environments.ini +++ b/environments.ini @@ -74,6 +74,7 @@ build_flags = '-DETH_PHY_MDC=23' '-DETH_PHY_MDIO=18' '-DETH_CLK_MODE=ETH_CLOCK_GPIO0_OUT' + '-DETH_PHY_COLD_CYCLE' '-DLED_ADDRESSABLE_PIN1=32' '-DLED_ADDRESSABLE_NUM=4' '-DLED_BROKER=0' @@ -113,6 +114,7 @@ build_flags = '-DETH_PHY_MDC=23' '-DETH_PHY_MDIO=18' '-DETH_CLK_MODE=ETH_CLOCK_GPIO0_OUT' + '-DETH_PHY_COLD_CYCLE' '-DLED_ADDRESSABLE=true' '-DLED_ADDRESSABLE_PIN1=32' '-DLED_ADDRESSABLE_NUM=4' diff --git a/main/main.cpp b/main/main.cpp index 21e67b2..1097149 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2475,6 +2475,19 @@ void setupWiFiManager() { void setup_ethernet_esp32() { bool ethBeginSuccess = false; WiFi.onEvent(WiFiEvent); +# if defined(ETH_PHY_COLD_CYCLE) && defined(ETH_PHY_POWER) && (ETH_PHY_POWER >= 0) + // Give the PHY a true cold start before begin(): a warm PHY left in a stale + // state (seen after an NVS erase with PSRAM enabled on Theengs Bridge v1.1) + // can flap the link until a manual power cycle, and the in-driver reset + // begin() performs (short assert, short delay) does not clear it. Power the + // PHY down, then back up, and let its oscillator settle before begin() + // starts talking to it. + pinMode(ETH_PHY_POWER, OUTPUT); + digitalWrite(ETH_PHY_POWER, LOW); + delay(200); // hold the PHY powered down + digitalWrite(ETH_PHY_POWER, HIGH); + delay(200); // let the PHY oscillator settle +# endif # ifdef NetworkAdvancedSetup THEENGS_LOG_TRACE(F("Adv eth cfg" CR)); // ETH.config() has to be called after ETH.begin(): the underlying netif is