esphome / issues

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

W5500 SPI-based Ethernet without interrupt pin causes crash at init #6268

Closed slakichi closed 3 weeks ago

slakichi commented 1 month ago

The problem

W5500 can build without interrupt_pin configuration, but actually, ESPHome firmware will setup W5500 ethernet driver with uninitialized interrupt pin config. This cause infinite crash at initialize ethernet component. Confirmed with M5Stack M5AtomS3 Lite with M5Stack ATOMIC PoE Base W5500

Which version of ESPHome has the issue?

2024.9.0

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

M5AtomS3 Lite

Component causing the issue

ethernet

Example YAML snippet

esphome:
  name: m5atoms3-lite
  platformio_options:
    board_build.f_cpu: 80000000L
    board_build.f_flush: 80000000L

esp32:
  board: esp32-s3-devkitc-1
  flash_size: 8MB
  variant: esp32s3
  framework:
    type: esp-idf
    version: "5.3.1"
    platform_version: "6.8.1"

network:
  enable_ipv6: False

ethernet:
  type: W5500
  clk_pin: GPIO5
  mosi_pin: GPIO8
  miso_pin: GPIO7
  cs_pin: GPIO6
  # W5500(SPI) optional pins
  #interrupt_pin:
  #reset_pin:
  clock_speed: 10MHz
  manual_ip:
    static_ip: 192.168.xxx.xxx
    gateway: 192.168.xxx.xxx
    subnet: 255.255.255.0
    dns1: 192.168.xxx.xxx

api:
  encryption:
    key: !secret home_assistant_api_password
  reboot_timeout: 300s

ota:
  platform: esphome
  password: !secret ota_password

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

sensor:
  - platform: uptime
    entity_category: diagnostic
  - platform: internal_temperature
    entity_category: diagnostic

Anything in the logs that might be useful for us?

[23:30:13]ELF file SHA256: c0251aa72
[23:30:13]
[23:30:13]Rebooting...
[23:30:13]ESP-ROM:esp32s3-20210327
[23:30:13]Build:Mar 27 2021
[23:30:13]rst:0xc (RTC_SW_CPU_RST),boot:0x28 (SPI_FAST_FLASH_BOOT)
[23:30:13]Saved PC:0x40376d7d
WARNING Decoded 0x40376d7d: esp_restart_noos at /home/slakichi/.platformio/packages/framework-espidf/components/esp_system/port/soc/esp32s3/system_internal.c:158
[23:30:13]SPIWP:0xee
[23:30:13]mode:DIO, clock div:1
[23:30:13]load:0x3fce2820,len:0x1918
[23:30:13]load:0x403c8700,len:0x4
[23:30:13]load:0x403c8704,len:0xdb4
[23:30:13]load:0x403cb700,len:0x304c
[23:30:13]entry 0x403c8924
[23:30:13]I (26) boot: ESP-IDF 5.3.1 2nd stage bootloader
[23:30:13]I (26) boot: compile time Sep 21 2024 23:26:24
[23:30:13]I (26) boot: Multicore bootloader
[23:30:13]I (27) boot: chip revision: v0.1
[23:30:13]I (27) qio_mode: Enabling default flash chip QIO
[23:30:13]I (27) boot.esp32s3: Boot SPI Speed : 80MHz
[23:30:13]I (27) boot.esp32s3: SPI Mode       : QIO
[23:30:13]I (27) boot.esp32s3: SPI Flash Size : 8MB
[23:30:13]I (28) boot: Enabling RNG early entropy source...
[23:30:13]I (28) boot: Partition Table:
[23:30:13]I (28) boot: ## Label            Usage          Type ST Offset   Length
[23:30:13]I (28) boot:  0 otadata          OTA data         01 00 00009000 00002000
[23:30:13]I (29) boot:  1 phy_init         RF data          01 01 0000b000 00001000
[23:30:13]I (29) boot:  2 app0             OTA app          00 10 00010000 003c0000
[23:30:13]I (29) boot:  3 app1             OTA app          00 11 003d0000 003c0000
[23:30:13]I (30) boot:  4 nvs              WiFi data        01 02 00790000 0006d000
[23:30:13]I (30) boot: End of partition table
[23:30:13]I (31) esp_image: segment 0: paddr=00010020 vaddr=3c0c0020 size=398b8h (235704) map
[23:30:13]I (67) esp_image: segment 1: paddr=000498e0 vaddr=3fc99400 size=03fe8h ( 16360) load
[23:30:13]I (70) esp_image: segment 2: paddr=0004d8d0 vaddr=40374000 size=02748h ( 10056) load
[23:30:13]I (72) esp_image: segment 3: paddr=00050020 vaddr=42000020 size=b5df0h (744944) map
[23:30:13]I (186) esp_image: segment 4: paddr=00105e18 vaddr=40376748 size=12bb4h ( 76724) load
[23:30:13]I (209) boot: Loaded app from partition at offset 0x10000
[23:30:13]I (209) boot: Disabling RNG early entropy source...
[23:30:13]I (210) cpu_start: Multicore app
[23:30:13]I (219) cpu_start: Pro cpu start user code
[23:30:13]I (219) cpu_start: cpu freq: 80000000 Hz
[23:30:13]I (219) app_init: Application information:
[23:30:13]I (220) app_init: Project name:     m5asl-bricky
[23:30:13]I (220) app_init: App version:      2024.9.0
[23:30:13]I (220) app_init: Compile time:     Sep 21 2024 23:26:07
[23:30:13]I (221) app_init: ELF file SHA256:  c0251aa72...
[23:30:13]I (221) app_init: ESP-IDF:          5.3.1
[23:30:13]I (221) efuse_init: Min chip rev:     v0.0
[23:30:13]I (221) efuse_init: Max chip rev:     v0.99
[23:30:13]I (222) efuse_init: Chip rev:         v0.1
[23:30:13]I (222) heap_init: Initializing. RAM available for dynamic allocation:
[23:30:13]I (222) heap_init: At 3FCA2BA8 len 00046B68 (282 KiB): RAM
[23:30:13]I (223) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
[23:30:13]I (223) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
[23:30:13]I (224) heap_init: At 600FE100 len 00001EE8 (7 KiB): RTCRAM
[23:30:13]I (225) spi_flash: detected chip: gd
[23:30:13]I (225) spi_flash: flash io: qio
[23:30:13]W (226) tsens: legacy driver is deprecated, please migrate to `driver/temperature_sensor.h`
[23:30:13]I (226) sleep: Configure to isolate all GPIO pins in sleep state
[23:30:13]I (227) sleep: Enable automatic switching of GPIO sleep configuration
[23:30:13]I (228) coexist: coex firmware version: 4482466
[23:30:13]I (228) coexist: coexist rom version e7ae62f
[23:30:13]I (229) main_task: Started on CPU0
[23:30:13]I (230) main_task: Calling app_main()
[23:30:13]I (284) main_task: Returned from app_main()
[23:30:13][I][logger:156]: Log initialized
[23:30:13][C][safe_mode:079]: There have been 3 suspected unsuccessful boot attempts
[23:30:13][D][esp32.preferences:114]: Saving 1 preferences to flash...
[23:30:13][D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[23:30:13][I][app:029]: Run[I][logger:156]: Log initialized
[23:30:13][C][safe_mode:079]: There have been 4 suspected unsuccessful boot attempts
[23:30:13][D][esp32.preferences:114]: Saving 1 preferences to flash...
[23:30:13][D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[23:30:13][I][app:029]: Running through setup()...
[23:30:13][C][esp32_ble:032]: Setting up BLE...
[23:30:13][C][ethernet:041]: Setting up Ethernet...
[23:30:13]Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
[23:30:13]
[23:30:13]Core  0 register dump:
[23:30:13]PC      : 0x4205c04c  PS      : 0x00060b33  A0      : 0x8205c511  A1      : 0x3fcac210
WARNING Decoded 0x4205c04c: gpio_ll_pullup_en at /home/slakichi/.platformio/packages/framework-espidf/components/hal/esp32s3/include/hal/gpio_ll.h:78
 (inlined by) gpio_pullup_en at /home/slakichi/.platformio/packages/framework-espidf/components/esp_driver_gpio/src/gpio.c:84
 (inlined by) gpio_pullup_en at /home/slakichi/.platformio/packages/framework-espidf/components/esp_driver_gpio/src/gpio.c:77
[23:30:13]A2      : 0x00000000  A3      : 0x00000000  A4      : 0x000000a5  A5      : 0x3fcb1610
[23:30:13]A6      : 0x3fc99468  A7      : 0x3fc9946c  A8      : 0x3c0ee79c  A9      : 0x0000001d
[23:30:13]A10     : 0x00000100  A11     : 0xffffffff  A12     : 0x3c0d6a4b  A13     : 0x00060b23
[23:30:13]A14     : 0x3c0d69c5  A15     : 0x0000cdcd  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
[23:30:13]EXCVADDR: 0x0000001d  LBEG    : 0x40056f08  LEND    : 0x40056f12  LCOUNT  : 0x00000000
[23:30:13]
[23:30:13]
[23:30:13]Backtrace: 0x4205c049:0x3fcac210 0x4205c50e:0x3fcac240 0x42060e99:0x3fcac270 0x4205fd63:0x3fcac2b0 0x4200ddc6:0x3fcac310 0x420ad3f5:0x3fcac410 0x420ad497:0x3fcac430 0x420117a2:0x3fcac450 0x420138dd:0x3fcac480 0x4200a31f:0x3fcac540
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x4205c049: gpio_ll_pullup_en at /home/slakichi/.platformio/packages/framework-espidf/components/hal/esp32s3/include/hal/gpio_ll.h:78
 (inlined by) gpio_pullup_en at /home/slakichi/.platformio/packages/framework-espidf/components/esp_driver_gpio/src/gpio.c:84
 (inlined by) gpio_pullup_en at /home/slakichi/.platformio/packages/framework-espidf/components/esp_driver_gpio/src/gpio.c:77
WARNING Decoded 0x4205c50e: gpio_set_pull_mode at /home/slakichi/.platformio/packages/framework-espidf/components/esp_driver_gpio/src/gpio.c:282
WARNING Decoded 0x42060e99: emac_w5500_init at /home/slakichi/.platformio/packages/framework-espidf/components/esp_eth/src/spi/w5500/esp_eth_mac_w5500.c:819
WARNING Decoded 0x4205fd63: esp_eth_driver_install at /home/slakichi/.platformio/packages/framework-espidf/components/esp_eth/src/esp_eth.c:231
WARNING Decoded 0x4200ddc6: esphome::ethernet::EthernetComponent::setup() at /home/slakichi/codespace/esphome/config/.esphome/build/m5asl-bricky/src/esphome/components/ethernet/ethernet_component.cpp:191
WARNING Decoded 0x420ad3f5: esphome::Component::call_setup() at /home/slakichi/codespace/esphome/config/.esphome/build/m5asl-bricky/src/esphome/core/component.cpp:78
WARNING Decoded 0x420ad497: esphome::Component::call() at /home/slakichi/codespace/esphome/config/.esphome/build/m5asl-bricky/src/esphome/core/component.cpp:104
WARNING Decoded 0x420117a2: esphome::Application::setup() at /home/slakichi/codespace/esphome/config/.esphome/build/m5asl-bricky/src/esphome/core/application.cpp:38
WARNING Decoded 0x420138dd: setup() at /home/slakichi/codespace/esphome/config/.esphome/build/m5asl-bricky/src/main.cpp:313
WARNING Decoded 0x4200a31f: esphome::loop_task(void*) at /home/slakichi/codespace/esphome/config/.esphome/build/m5asl-bricky/src/esphome/components/esp32/core.cpp:67

Additional information

This may cause by uninitialized EthernetComponent::interrupt_pin_ (and not supported polling mode). Workaround Fix (polling interval is set sloppy and this causes the ESP32 core with high temperature(~75C), but it works)

--- ethernet_component.cpp      2024-09-22 14:35:08.937943069 +0900
+++ ethernet_component.cpp      2024-09-22 00:04:16.031128356 +0900
@@ -118,6 +118,15 @@
   w5500_config.int_gpio_num = this->interrupt_pin_;
   phy_config.phy_addr = this->phy_addr_spi_;
   phy_config.reset_gpio_num = this->reset_pin_;
+  if (w5500_config.int_gpio_num < 0 && w5500_config.poll_period_ms == 0) {
+    // calcurate from clock speed
+    if (this->clock_speed_ > 0) {
+      w5500_config.poll_period_ms = 80000000UL / this->clock_speed_;
+    }
+    if (w5500_config.poll_period_ms == 0) {
+      w5500_config.poll_period_ms = 1;
+    }
+  }

   esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
 #else
@@ -314,7 +323,7 @@
   ESP_LOGCONFIG(TAG, "  MISO Pin: %u", this->miso_pin_);
   ESP_LOGCONFIG(TAG, "  MOSI Pin: %u", this->mosi_pin_);
   ESP_LOGCONFIG(TAG, "  CS Pin: %u", this->cs_pin_);
-  ESP_LOGCONFIG(TAG, "  IRQ Pin: %u", this->interrupt_pin_);
+  ESP_LOGCONFIG(TAG, "  IRQ Pin: %d", this->interrupt_pin_);
   ESP_LOGCONFIG(TAG, "  Reset Pin: %d", this->reset_pin_);
   ESP_LOGCONFIG(TAG, "  Clock Speed: %d MHz", this->clock_speed_ / 1000000);
 #else
--- ethernet_component.h        2024-09-22 14:35:21.067973882 +0900
+++ ethernet_component.h        2024-09-21 23:35:05.449671506 +0900
@@ -107,7 +107,7 @@
   uint8_t miso_pin_;
   uint8_t mosi_pin_;
   uint8_t cs_pin_;
-  uint8_t interrupt_pin_;
+  int interrupt_pin_{-1};
   int reset_pin_{-1};
   int phy_addr_spi_{-1};
   int clock_speed_;
ssieb commented 1 month ago

I started to create a PR and then I noticed that you had already shown the required change. Why don't you make a PR?

slakichi commented 1 month ago
  1. I am new to git
  2. poll_period_ms should be configurable (but I'm hassle with it)
ivanduka commented 1 month ago

@slakichi, it's very simple to create a PR, you'll need to fork the repo, create a new branch from main, do the changes and commit them, then push the branch to GitHub, create a new Pull Request and choose your branch as the source.

cortices commented 1 month ago

I was just coming here to make the same change, @slakichi if you don't mind I am happy to open this PR?

slakichi commented 1 month ago

Everyone seemed to want me to submit a PR, so I submitted a Draft, putting the document out of my mind. ... There seemed to be an error immediately.

cortices commented 1 month ago

There's no error, it's just waiting for review :) Thanks!