LAN8720 does not appear to be restarting (Need to recycle the power supply)

rtek1000
Posts: 2
Joined: Sat Mar 14, 2020 5:44 am

LAN8720 does not appear to be restarting (Need to recycle the power supply)

Postby rtek1000 » Sat Mar 14, 2020 6:00 am

I managed to get the LAN8720 board to work with STM32F407VG using STM32CubeIDE and Arduino IDE, but I'm not having complete success with ESP32.

I am using this wire connection sequence:
GPIO17 - PHY_POWER : NC - Osc. Enable - 4k7 Pulldown
GPIO22 - EMAC_TXD1 : TX1
GPIO19 - EMAC_TXD0 : TX0
GPIO21 - EMAC_TX_EN : TX_EN
GPIO26 - EMAC_RXD1 : RX1
GPIO25 - EMAC_RXD0 : RX0
GPIO27 - EMAC_RX_DV : CRS
GPIO00 - EMAC_TX_CLK : nINT/REFCLK (50MHz) - 4k7 Pullup
GPIO23 - SMI_MDC : MDC
GPIO18 - SMI_MDIO : MDIO
GND : GND
3V3 : VCC
Source: https://sautter.com/blog/ethernet-on-es ... g-lan8720/

And I set up the sample sketch for these settings:
(P.S.: Do not use this example, see the corrected code below)

Code: Select all

/*
    This sketch shows the Ethernet event usage

*/

#include <ETH.h>

#ifdef ETH_CLK_MODE
#undef ETH_CLK_MODE
#endif
#define ETH_CLK_MODE    ETH_CLOCK_GPIO0_IN

// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_POWER_PIN   17

// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE        ETH_PHY_LAN8720

// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR        1

// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN     23

// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN    18

static bool eth_connected = false;

void WiFiEvent(WiFiEvent_t event)
{
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      if (ETH.fullDuplex()) {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case SYSTEM_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default:
      break;
  }
}

void testClient(const char * host, uint16_t port)
{
  Serial.print("\nconnecting to ");
  Serial.println(host);

  WiFiClient client;
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    return;
  }
  client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
  while (client.connected() && !client.available());
  while (client.available()) {
    Serial.write(client.read());
  }

  Serial.println("closing connection\n");
  client.stop();
}

void setup()
{
//  pinMode(ETH_POWER_PIN, OUTPUT);
//  digitalWrite(ETH_POWER_PIN, HIGH);
  Serial.begin(115200);
  WiFi.onEvent(WiFiEvent);
  ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
}


void loop()
{
  if (eth_connected) {
    testClient("google.com", 80);
  }
  delay(10000);
}
Source: https://github.com/espressif/arduino-es ... AN8720.ino

But whenever I press the reset button, or after the IDE finishes uploading the sketch, only those outputs appear and appear to be stuck:
02:02:07.939 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
02:02:07.939 -> configsip: 0, SPIWP:0xee
02:02:07.939 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
02:02:07.939 -> mode:DIO, clock div:1
02:02:07.939 -> load:0x3fff0018,len:4
02:02:07.939 -> load:0x3fff001c,len:1216
02:02:07.939 -> ho 0 tail 12 room 4
02:02:07.939 -> load:0x40078000,len:9720
02:02:07.939 -> ho 0 tail 12 room 4
02:02:07.939 -> load:0x40080400,len:6352
02:02:07.939 -> entry 0x400806b8
02:02:08.220 -> ETH Started
For STM32, when I pressed the reset button, the LEDs flashed (from the RJ45 connector on the LAN8720). But when pressing the reset of the ESP32, the same behavior does not occur with the LEDs.

So I turned off the power, removed the USB cable, and then reconnected the cable. After turning the power back on, the LAN8720 card worked, and a response was received from the internet.

In this way I conclude that there is no reset of the LAN8720.

I tried to locate the LAN8720 init source code, but it appears to be precompiled in binary format, file libethernet.a

How can I solve this?

Thank you.
Last edited by rtek1000 on Sun Mar 15, 2020 12:27 am, edited 1 time in total.

rtek1000
Posts: 2
Joined: Sat Mar 14, 2020 5:44 am

Re: LAN8720 does not appear to be restarting (Need to recycle the power supply)

Postby rtek1000 » Sun Mar 15, 2020 12:26 am

Problem encountered (and the solution):

https://github.com/espressif/arduino-esp32/issues/3817

Who is online

Users browsing this forum: MichaelS and 91 guests