FYI - network not working after ESP.restart()

Started by mihaiadrian, November 12, 2023, 04:07:12 AM

Previous topic - Next topic

mihaiadrian

Ok, so today I encountered and issue with ESP32 .  I was working fine with a 24 port Tp-link switch but NOT with a  Ubiquiti POE passthrough switch - after ESP.restart() there was no network. This was very annoying since I had to cut the switch power remotely in order to make the board back online.

I read this 2 links:
https://github.com/espressif/esp-idf/issues/5965
https://www.eevblog.com/forum/microcontrollers/no-ethernet-phy-connectivity-with-esp-32-wroom/25/
and found this workaround:


// workaround - some POE switches need this ....
void toggleNetwork() {
  pinMode(ETH_PHY_POWER, INPUT);
  digitalWrite(ETH_PHY_POWER, 0);
  pinMode(ETH_PHY_POWER, OUTPUT);
  delay(99);
}

void restartBoard() {
  toggleNetwork();
  ESP.restart();
}

So I call toggleNetwork before ETH.begin()  and  restartBoard() when I want to do a restart. With this 2 it seems to works fine for me , on both switches. ( only tested remotely ... hopefully I am not wrong )

Have fun.

LubOlimex

Thanks for this info, and solution. However I think it is the function that you used that is the problem and the requirement of LAN getting initialized only after ESP32 had been initialized (so that it gets clock upon turning on). The Ethernet clock is generated by the ESP32.

1. Can you try to use ESP.reset() instead of ESP.restart() ?

2. Maybe instead of ESP.reset() and ESP.restart() can you try to toggle ESP_EN via your code?

Remember you have to take care of the sequence of powering. Ethernet has to start after ESP32's PHY clock is available.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_eth.html

Technical support and documentation manager at Olimex

mihaiadrian

Quote from: LubOlimex on November 13, 2023, 09:12:51 AM1. Can you try to use ESP.reset() instead of ESP.restart() ?

In function 'void restartBoard()':
error: 'class EspClass' has no member named 'reset'; did you mean 'restart'?
   ESP.reset();
       ^~~~~
       restart

so I only have restart function available.

LubOlimex

#3
There was hardware reset for ESP8266 it was performed ESP.reset(), maybe it is not available for the ESP32. Huh, anyway software reset via ESP.restart() probably does exactly what I explained. It doesn't restart the Ethernet chip meaning it hangs (because it has no clock source) after the ESP32 chip performs software reset.
Technical support and documentation manager at Olimex

KeviNH

I added the following in setup(), now ESP32-POE reliably gets Ethernet connection and  on restart:

 
    delay(350);
    pinMode(ETH_PHY_POWER, OUTPUT);
    digitalWrite(ETH_PHY_POWER, LOW);
    delay(200);
    int success = ETH.begin();


Is there a better way to ensure that Ethernet doesn't start until after ESP32's PHY clock is available?

LubOlimex

This is the best way, it is the reason to have a phy power enable/disable pin in first place.
Technical support and documentation manager at Olimex