Skip to content

DHCP issue with ESP32 and RTL8201F #7795

Closed as not planned
Closed as not planned
@0x0fe

Description

@0x0fe

Board

ESP32 Dev Module

Device Description

Proprietary board using ESP32-WROOM-32E module, RTL8201F PHY with HR911105A magjack.

Hardware Configuration

First iteration of this board uses 50MHz active oscillator to GPIO0 for PHY CLK.
Current revision uses APLL for PHY CLK from GPIO17 (no active crystal oscillator).
As a side note the hard mapping of PHY CLK to GPIO0 is really a bad design decision, not only it interferes with bootstrap process but it also seems GPIO0 has issues when fed with 25 or 50M signal, and it is the only option when using crystal oscillator since GPIO16 and 17 can only be used as APLL outputs. I had to give up on using GPIO0 and crystal oscillator, in favor of APLL clock on GPIO17, which is really not ideal.

Version

v2.0.6

IDE Name

arduino IDE

Operating System

windows 10

Flash frequency

80M

PSRAM enabled

no

Upload speed

921600

Description

So, when the debug level is set to verbose, the DHCP is correctly initiated, the IP is assigned almost instantly as expected.
However, when the debug level is set to warning, error or none, then the DHCP process fails, no IP is assigned and it sits here forever, so no further attempt of DHCP acquisition is done, apparently.
So it very much looks like a timing / interlock issue, also i cannot understand why there is no mechanism to reinitiate the DHCP acquisition when it (silently) fails.
This behaviour is reproductible and consistent.

I have not found a way to force DHCP acquisition, otherwise i could do it manually after a timeout.
I can set static IP and it works, but that is a not a solution since static IP is not applicable in some case.

I believe this other issue #5733 is probably related.

Sketch

#include <Arduino.h>
#include <ETH.h>

//#define ETH_CLK_MODE    ETH_CLOCK_GPIO0_IN  
#define ETH_CLK_MODE    ETH_CLOCK_GPIO17_OUT
#define ETH_TYPE        ETH_PHY_RTL8201 
#define ETH_POWER_PIN   5
#define ETH_ADDR        0x00 
#define ETH_MDC_PIN     23
#define ETH_MDIO_PIN    18

static bool eth_connected=false;
unsigned long c=0;

void EthEvent(WiFiEvent_t event){
  
  switch (event)
  {
    case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      ETH.setHostname("esp32-ethernet");
    break;
    case ARDUINO_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
    break;
    case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.println(ETH.macAddress());
      Serial.print("IPv4: ");
      Serial.println(ETH.localIP());
      if (ETH.fullDuplex()){
        Serial.print("FULL_DUPLEX");
      }
      Serial.print(" ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
    break;
    case ARDUINO_EVENT_ETH_DISCONNECTED:
      Serial.println("\nETH Disconnected");
      eth_connected = false;
    break;
    case ARDUINO_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
    break;
    default:
    break;
  }
}
void testClient(const char *host, uint16_t port) {
  
  Serial.print("connect ");
  Serial.print(host);

  WiFiClient client;
  if (!client.connect(host, port)) {
    Serial.println(" ... failed");
    return;
  }
  client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
  while (client.connected() && !client.available());
  while (client.available()) client.read();
  Serial.println(" ... closing");
  client.stop();
}
void setup() {
  
  Serial.begin(115200);
  WiFi.onEvent(EthEvent);
  delay(100);
  ETH.begin(ETH_ADDR,ETH_POWER_PIN,ETH_MDC_PIN,ETH_MDIO_PIN,ETH_TYPE,ETH_CLK_MODE);
  delay(100);
 //ETH.config(IPAddress(192,168,1,188),IPAddress(192,168,1,1),IPAddress(255,255,255,0),IPAddress(192,168,1,1));
}
void loop() {
  
  if(eth_connected && c++>200) {
    testClient("www.google.com", 80);
    c=0;
  }
  delay(5);
}

Debug Message

ETH Started
ETH Connected

Other Steps to Reproduce

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions