esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

ESP32 and W5500 - COMPLETE FAILURE OF COMPONENT #6193

Open ESP32andmore opened 2 months ago

ESP32andmore commented 2 months ago

The problem

Using a ESP32 with the W5500 Ethernet chip, ESPHome fails to initialize device. The hardware has been verified to be fully functional with a Arduino sketch using WebServer_ESP32_W5500 lib @25mhz.

Which version of ESPHome has the issue?

2204.8.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

Most recent

What platform are you using?

ESP32

Board

Coolboxx II, ESP-DEV-Module

Component causing the issue

W5500

Example YAML snippet

substitutions:
  devicename: avfan1eth
  fdevicename: AVfan1eth
  ip: 192.168.0.201 # For static IP adressing

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  alarm_temp: "50" # Threshold for alarm when implemented
  ptemp: "20"
  itemp: "0.1"

# Connect your Dallas sensors with logger: DEBUG enabled (factory flash default).
# Open the ESPHome webtool, connect to the ECB board, view the "Logs" window, hit "Reset",
# and search for Dallas scan addresses and replace the below addresses with your unique ones.
# Example Scan
#[18:16:42][D][dallas.sensor:084]:     0x8b3ca8f64935b228 4
#[18:16:42][D][dallas.sensor:084]:     0x783c0af6490d3628 2
#[18:16:42][D][dallas.sensor:084]:     0xc13c01f09642c928 1
#[18:16:42][D][dallas.sensor:084]:     0x043c6ef649772f28 3
  dallasaddress1: "0xc13c01f09642c928"
  dallasaddress2: "0x783c0af6490d3628"
  dallasaddress3: "0x043c6ef649772f28"
  dallasaddress4: "0x8b3ca8f64935b228"

#external_components:
#  - source:
#      type: git
#      url: https://github.com/ssieb/esphome
#      ref: onewire
#    components: [ one_wire, gpio ]
#    refresh: 1min

esphome:
  name: ${devicename}
  friendly_name: ${fdevicename}

  on_boot:
  - priority: 900.0
    then:
      - lambda: |-
          id(cpu_speed) = ESP.getCpuFreqMHz();

esp32:
  board: wemos_d1_mini32
  framework:
    type: arduino

preferences:
  flash_write_interval: 10min

ethernet:
  type: W5500
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19
  cs_pin: GPIO15
  interrupt_pin: GPIO36
  reset_pin: GPIO26
  manual_ip:
    static_ip: ${ip}
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 192.168.0.1
    dns2: 8.8.8.8

...

Anything in the logs that might be useful for us?

[C][ethernet:041]: Setting up Ethernet...
[D][esp-idf:000]: E (871) w5500.mac: w5500_reset(221): reset timeout

[D][esp-idf:000]: E (872) w5500.mac: emac_w5500_init(602): reset w5500 failed

[D][esp-idf:000]: E (882) esp_eth: esp_eth_driver_install(214): init mac failed

[E][ethernet:192]: ETH driver install error: (263) ESP_ERR_TIMEOUT
[E][component:119]: Component ethernet was marked as failed.
[E][component:164]: Component ethernet set Error flag: unspecified

Then:

[D][esp-idf:000][w5500_tsk]: E (4791) spi_master: check_trans_valid(689): txdata transfer > host maximum

[D][esp-idf:000][w5500_tsk]: E (4802) w5500.mac: w5500_read(97): spi transmit failed

[D][esp-idf:000][w5500_tsk]: E (4802) w5500.mac: w5500_read_buffer(188): read RX buffer failed

[D][esp-idf:000][w5500_tsk]: E (4813) w5500.mac: emac_w5500_receive(572): read payload failed, len=65533, offset=1


Then:

[D][esp-idf:000][w5500_tsk]: E (4791) spi_master: check_trans_valid(689): txdata transfer > host maximum

[D][esp-idf:000][w5500_tsk]: E (4802) w5500.mac: w5500_read(97): spi transmit failed

[D][esp-idf:000][w5500_tsk]: E (4802) w5500.mac: w5500_read_buffer(188): read RX buffer failed

[D][esp-idf:000][w5500_tsk]: E (4813) w5500.mac: emac_w5500_receive(572): read payload failed, len=65533, offset=1


Then:

Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception). 
Debug exception reason: Stack canary watchpoint triggered (w5500_tsk) 
Core  1 register dump:
PC      : 0x4008eeff  PS      : 0x00060036  A0      : 0x8008d9e8  A1      : 0x3ffca0b0
A2      : 0x3ffbefe8  A3      : 0xb33fffff  A4      : 0x0000cdcd  A5      : 0x00060023
A6      : 0x00060023  A7      : 0x0000abab  A8      : 0xb33fffff  A9      : 0xffffffff
A10     : 0x3f40f6f2  A11     : 0x00000000  A12     : 0x8008515e  A13     : 0x3ffbef3c
A14     : 0x007befe8  A15     : 0x003fffff  SAR     : 0x00000004  EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000  LBEG    : 0x400899b9  LEND    : 0x400899c9  LCOUNT  : 0xffffffff

Backtrace:0x4008eefc:0x3ffca0b00x4008d9e5:0x3ffca0f0 0x4008c148:0x3ffca120 0x4008c0f8:0xa5a5a5a5  |<-CORRUPTED

ELF file SHA256: 0000000000000000

Rebooting...

Additional information

Hardware works without error with this Arduino Sketch:

/**** WebServer.ino - Simple Arduino web server sample for Ethernet shield

For Ethernet shields using ESP32_W5500 (ESP32 + W5500)

WebServer_ESP32_W5500 is a library for the ESP32 with Ethernet W5500 to run WebServer

Based on and modified from ESP32-IDF https://github.com/espressif/esp-idf Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_W5500 Licensed under GPLv3 license *****/

if !( defined(ESP32) )

error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.

endif

define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4

define _ETHERNET_WEBSERVERLOGLEVEL 3

//////////////////////////////////////////////////////////

// Optional values to override default settings // Don't change unless you know what you're doing //#define ETH_SPI_HOST SPI3_HOST

define SPI_CLOCK_MHZ 25

// Must connect INT to GPIOxx or not working

define INT_GPIO 36

//#define MISO_GPIO 19 //#define MOSI_GPIO 23 //#define SCK_GPIO 18 //#define CS_GPIO 5

//////////////////////////////////////////////////////////

include

WiFiServer server(80);

// Enter a MAC address and IP address for your controller below.

define NUMBER_OF_MAC 20

byte mac[][NUMBER_OF_MAC] = { { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, };

// Select the IP address according to your local network IPAddress myIP(192, 168, 0, 201); IPAddress myGW(192, 168, 0, 1); IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP IPAddress myDNS(8, 8, 8, 8);

int reqCount = 0; // number of requests received

void setup() { Serial.begin(115200);

while (!Serial && (millis() < 5000));

Serial.print(F("\nStart WebServer on ")); Serial.print(ARDUINO_BOARD); Serial.print(F(" with ")); Serial.println(SHIELD_TYPE); Serial.println(WEBSERVER_ESP32_W5500_VERSION);

ET_LOGWARN(F("Default SPI pinout:")); ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST); ET_LOGWARN1(F("MOSI:"), MOSI_GPIO); ET_LOGWARN1(F("MISO:"), MISO_GPIO); ET_LOGWARN1(F("SCK:"), SCK_GPIO); ET_LOGWARN1(F("CS:"), CS_GPIO); ET_LOGWARN1(F("INT:"), INT_GPIO); ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ); ET_LOGWARN(F("========================="));

///////////////////////////////////

// To be called before ETH.begin() ESP32_W5500_onEvent();

// start the ethernet connection and the server: // Use DHCP dynamic IP and random mac //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ, // int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac); ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST ); //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );

// Static IP, leave without this line to get IP via DHCP //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); ETH.config(myIP, myGW, mySN, myDNS);

ESP32_W5500_waitForConnect();

///////////////////////////////////

// start the web server on port 80 server.begin(); }

void loop() { // listen for incoming clients WiFiClient client = server.available();

if (client) { Serial.println(F("New client")); // an http request ends with a blank line bool currentLineIsBlank = true;

while (client.connected())
{
  if (client.available())
  {
    char c = client.read();
    Serial.write(c);

    // if you've gotten to the end of the line (received a newline
    // character) and the line is blank, the http request has ended,
    // so you can send a reply
    if (c == '\n' && currentLineIsBlank)
    {
      Serial.println(F("Sending response"));

      // send a standard http response header
      // use \r\n instead of many println statements to speedup data send
      client.print(
        "HTTP/1.1 200 OK\r\n"
        "Content-Type: text/html\r\n"
        "Connection: close\r\n"  // the connection will be closed after completion of the response
        "Refresh: 20\r\n"        // refresh the page automatically every 20 sec
        "\r\n");
      client.print("<!DOCTYPE HTML>\r\n");
      client.print("<html>\r\n");
      client.print(String("<h2>Hello World from ESP32andmore.com") + "!</h2>\r\n");
      client.print("Requests received: ");
      client.print(++reqCount);
      client.print("<br>\r\n");
      client.print("<br>\r\n");
      client.print("</html>\r\n");
      break;
    }

    if (c == '\n')
    {
      // you're starting a new line
      currentLineIsBlank = true;
    }
    else if (c != '\r')
    {
      // you've gotten a character on the current line
      currentLineIsBlank = false;
    }
  }
}

// give the web browser time to receive the data
delay(10);

// close the connection:
client.stop();
Serial.println(F("Client disconnected"));

} }

functionpointer commented 1 month ago

Same issue here

[01:03:36][E][mlx90393:085]: failed to read data
[01:03:36][E][mlx90393:085]: failed to read data
[01:03:36][E][mlx90393:085]: failed to read data
[01:03:36][E][mlx90393:085]: failed to read data
[01:03:37][E][mlx90393:085]: failed to read data
[01:03:37][I][ethernet:247]: Connected via Ethernet!
[01:03:37][C][ethernet:492]:   IP Address: 10.10.11.98
[01:03:37][C][ethernet:493]:   Hostname: 'elec-gas-meter'
[01:03:37][C][ethernet:494]:   Subnet: 255.255.255.0
[01:03:37][C][ethernet:495]:   Gateway: 10.10.11.1
[01:03:37][C][ethernet:500]:   DNS1: 0.0.0.0
[01:03:37][C][ethernet:501]:   DNS2: 0.0.0.0
[01:03:37][C][ethernet:513]:   MAC Address: 7C:9E:BD:ED:41:98
[01:03:37][C][ethernet:514]:   Is Full Duplex: YES
[01:03:37][C][ethernet:515]:   Link Speed: 100
[01:03:37][W][component:170]: Component ethernet cleared Warning flag
[01:03:37][C][mqtt:037]: Setting up MQTT...
[01:03:37][W][component:157]: Component mqtt set Warning flag: unspecified
[01:03:37][I][mqtt:244]: Connecting to MQTT...
[01:03:37][E][mlx90393:085]: failed to read data
[01:03:37][E][mlx90393:085]: failed to read data
[01:03:37][E][mlx90393:085]: failed to read data
[01:03:38][E][mlx90393:085]: failed to read data
[01:03:38]Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception).
[01:03:38]Debug exception reason: Stack canary watchpoint triggered (w5500_tsk)
[01:03:38]Core  0 register dump:
[01:03:38]PC      : 0x400928a7  PS      : 0x00060836  A0      : 0x4008b30e  A1      : 0x3ffae820
WARNING Decoded 0x400928a7: xthal_save_extra_nw at /Users/igrokhotkov/e/esp32/hal/hal/state_asm.S:72
[01:03:38]A2      : 0x3ffae890  A3      : 0xb33fffff  A4      : 0x3ffaeaf0  A5      : 0x00000000
[01:03:38]A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffae8f0
[01:03:38]A10     : 0x3ffae8f0  A11     : 0x3f401e42  A12     : 0x000000ff  A13     : 0x0000ff00
[01:03:38]A14     : 0x00000007  A15     : 0xff000000  SAR     : 0x00000008  EXCCAUSE: 0x00000001
[01:03:38]EXCVADDR: 0x00000000  LBEG    : 0x40089029  LEND    : 0x40089039  LCOUNT  : 0xfffffffe
[01:03:38]
[01:03:38]
[01:03:38]Backtrace: 0x400928a4:0x3ffae820 0x4008b30b:0x3ffaebf0 0x401534da:0x3ffaec80 0x400d6a85:0x3ffaecc0 0x400d6ab9:0x3ffaecf0 0x400d6b15:0x3ffaed40 0x400d6c3d:0x3ffaed70 0x400de20e:0x3ffaed90 0x4015f881:0x3ffaedd0 0x4011a85a:0x3ffaee00 0x4011a8f7:0x3ffaee30 0x400e70ba:0x3ffaeeb0 0x400e7afa:0x3ffaeee0 0x400e7c54:0x3ffaef10 0x400f5f78:0x3ffaef30 0x400f602e:0x3ffaef90 0x400f6d4b:0x3ffaefc0 0x400f61f6:0x3ffaf000
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x400928a4: xthal_save_extra_nw at /Users/igrokhotkov/e/esp32/hal/hal/state_asm.S:72
WARNING Decoded 0x4008b30b: _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:159
WARNING Decoded 0x401534da: vsnprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vsnprintf.c:40
WARNING Decoded 0x400d6a85: esphome::logger::Logger::vprintf_to_buffer_(char const*, __va_list_tag) at C:\Users\Fubbel\git\gas-meter\.esphome\build\elec-gas-meter/src/esphome/components/logger/logger.h:124
WARNING Decoded 0x400d6ab9: esphome::logger::Logger::printf_to_buffer_(char const*, ...) at C:\Users\Fubbel\git\gas-meter\.esphome\build\elec-gas-meter/src/esphome/components/logger/logger.h:138
WARNING Decoded 0x400d6b15: esphome::logger::Logger::write_header_(int, char const*, int) at C:\Users\Fubbel\git\gas-meter\.esphome\build\elec-gas-meter/src/esphome/components/logger/logger.cpp:56
WARNING Decoded 0x400d6c3d: esphome::logger::Logger::log_vprintf_(int, char const*, int, char const*, __va_list_tag) at C:\Users\Fubbel\git\gas-meter\.esphome\build\elec-gas-meter/src/esphome/components/logger/logger.cpp:67
WARNING Decoded 0x400de20e: esphome::esp_idf_log_vprintf_(char const*, __va_list_tag) at C:\Users\Fubbel\git\gas-meter\.esphome\build\elec-gas-meter/src/esphome/core/log.cpp:56
WARNING Decoded 0x4015f881: esp_log_writev at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/log/log.c:200
WARNING Decoded 0x4011a85a: __wrap_esp_log_writev at /Users/ficeto/Desktop/ESP32/ESP32S2/esp32-arduino-lib-builder/components/esp-insights/components/esp_diagnostics/src/esp_diagnostics_log_hook.c:452
WARNING Decoded 0x4011a8f7: __wrap_esp_log_write at /Users/ficeto/Desktop/ESP32/ESP32S2/esp32-arduino-lib-builder/components/esp-insights/components/esp_diagnostics/src/esp_diagnostics_log_hook.c:469
WARNING Decoded 0x400e70ba: check_trans_valid at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/driver/spi_master.c:716 (discriminator 7)
WARNING Decoded 0x400e7afa: spi_device_polling_start at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/driver/spi_master.c:931 (discriminator 2)
WARNING Decoded 0x400e7c54: spi_device_polling_transmit at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/driver/spi_master.c:1000
WARNING Decoded 0x400f5f78: w5500_read at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_eth/src/esp_eth_mac_w5500.c:96
WARNING Decoded 0x400f602e: w5500_read_buffer at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_eth/src/esp_eth_mac_w5500.c:192
WARNING Decoded 0x400f6d4b: emac_w5500_receive at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_eth/src/esp_eth_mac_w5500.c:572 (discriminator 2)
WARNING Decoded 0x400f61f6: emac_w5500_task at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_eth/src/esp_eth_mac_w5500.c:339
[01:03:38]
[01:03:38]
[01:03:38]
[01:03:38]
[01:03:38]ELF file SHA256: 97715b38086b31e7
[01:03:38]
[01:03:38]E (3802) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0
[01:03:38]Rebooting...
[01:03:38]ets Jun  8 2016 00:22:57
[01:03:38]
[01:03:38]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[01:03:38]configsip: 0, SPIWP:0xee
[01:03:38]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[01:03:38]mode:DIO, clock div:2
[01:03:38]load:0x3fff0030,len:1184
[01:03:38]load:0x40078000,len:13192
[01:03:38]load:0x40080400,len:3028
[01:03:38]entry 0x400805e4
[01:03:38]E (361) esp_core_dump_flash: No core d\xf5f\x9e\x81partition found!
[01:03:38]E (361) esp_core_dump_flash: No core dump partition found!
[01:03:38][I][logger:156]: Log initialized
[01:03:38][C][safe_mode:079]: There have been 5 suspected unsuccessful boot attempts
[01:03:38][D][esp32.preferences:114]: Saving 1 preferences to flash...
[01:03:38][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[01:03:38][I][app:029]: Running through setup()...
[01:03:38][I][i2c.arduino:218]: Performing I2C bus recovery
[01:03:38][C][ethernet:041]: Setting up Ethernet...
functionpointer commented 1 month ago

Turns out the SPI frequency was too fast for my wiring. Fixed by reducing it:

ethernet:
  type: W5500
  clk_pin: 19
  mosi_pin: 26
  miso_pin: 23
  cs_pin: 27
  interrupt_pin: 22
  reset_pin: 18
  clock_speed: 8MHz
  manual_ip:
    static_ip: 10.10.11.94
    gateway: 10.10.11.1
    subnet: 255.255.255.0