W5500 Resets Chip without error if anything in the SPI connection is faulty.

AG_OHP
Posts: 9
Joined: Mon Oct 10, 2022 7:28 am

W5500 Resets Chip without error if anything in the SPI connection is faulty.

Postby AG_OHP » Fri Nov 08, 2024 11:29 am

CHIP: ESP32S3
ESP-IDF

Hi, I know this probably would have been better off in the issue page, but at this point im not aware if maybe there is a good reason for it.
When initializing the W5500 it works fine, as long as the SPI communication is stable. The moment the SPI communication does not work, (Bus not initialized, Wrong impedance etc.) the code crashes, and the chip restarts.

This is not ideal. I would prefer a normal error, so that if the module fails, we can just take the error and react.

Right now i would have to set a flag before trying the initialization and check wether this has failed in the last run.
This is maybe possible, but i would prefer a normal error so i can react to that error and do not have to suffer a restart to see if it is working.

The error happens here:
  1. /**
  2.  * @brief Ethernet SPI modules initialization
  3.  * @pre
  4.  * @param[in] eth_driver_config specific SPI Ethernet module configuration
  5.  * @param[out] mac_out optionally returns Ethernet MAC object
  6.  * @param[out] phy_out optionally returns Ethernet PHY object
  7.  * @return
  8.  *          || esp_eth_handle_t if init succeeded
  9.  *          || NULL if init failed
  10.  */
  11. static esp_eth_handle_t eth_cnct_install_w5500_driver(eth_cnct_driver_config_t *eth_driver_config, esp_eth_mac_t **mac_out, esp_eth_phy_t **phy_out)
  12. {
  13.     esp_eth_handle_t ret = NULL;
  14.     // Init common MAC and PHY configs to default
  15.     eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  16.     eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
  17.     // Update PHY config based on board specific configuration
  18.     phy_config.phy_addr       = eth_driver_config->phy_addr;
  19.     phy_config.reset_gpio_num = eth_driver_config->phy_reset_gpio;
  20.     // Configure SPI interface for specific SPI module
  21.     spi_device_interface_config_t spi_devcfg
  22.         = { .mode = 0, .clock_speed_hz = ETH_CNCT_SPI_CLOCK_MHZ * 1000 * 1000, .queue_size = 20, .spics_io_num = eth_driver_config->spi_cs_gpio };
  23.  
  24.     // Init vendor specific MAC config to default, and create new SPI Ethernet MAC
  25.     // instance and new PHY instance based on board configuration
  26.     eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(ETH_CNCT_SPI_HOST, &spi_devcfg);
  27.     w5500_config.int_gpio_num       = eth_driver_config->int_gpio;
  28.     esp_eth_mac_t *mac              = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
  29.     esp_eth_phy_t *phy              = esp_eth_phy_new_w5500(&phy_config);
  30.  
  31.     // Init Ethernet driver to default and install it
  32.     esp_eth_handle_t w5500_eth_handle = NULL;
  33.     esp_eth_config_t eth_config_spi   = ETH_DEFAULT_CONFIG(mac, phy);
  34.  
  35. #if 1 // debug
  36.     ESP_LOGI("DEBUG", "We reach this point (before esp_eth_driver_install)");
  37.     vTaskDelay(100 / portTICK_PERIOD_MS); // Delay to make sure the UART Queue has time to be emptied into the Serial Monitor
  38. #endif
  39.  
  40.     ESP_GOTO_ON_FALSE(ESP_OK == esp_eth_driver_install(&eth_config_spi, &w5500_eth_handle), NULL, err, TAG, "SPI Ethernet driver install failed");
  41.  
  42. #if 1 // debug
  43.     ESP_LOGI("DEBUG", "We never reach this point (After esp_eth_driver_install)");
  44. #endif
  45.  
  46.  
  47.     // The SPI Ethernet module does not have a burned factory MAC address, we can
  48.     // set it manually.
  49.     if (eth_driver_config->mac_addr != NULL)
  50.     {
  51.         ESP_GOTO_ON_FALSE(ESP_OK == esp_eth_ioctl(w5500_eth_handle, ETH_CMD_S_MAC_ADDR, eth_driver_config->mac_addr),
  52.                           NULL,
  53.                           err,
  54.                           TAG,
  55.                           "SPI Ethernet MAC address config failed");
  56.     }
  57.  
  58.     if (mac_out != NULL) { *mac_out = mac; }
  59.     if (phy_out != NULL) { *phy_out = phy; }
  60.     return w5500_eth_handle;
  61. err:
  62.     if (w5500_eth_handle != NULL) { esp_eth_driver_uninstall(w5500_eth_handle); }
  63.     if (mac != NULL) { mac->del(mac); }
  64.     if (phy != NULL) { phy->del(phy); }
  65.     return ret;
precisely here:
  1. #if 1 // debug
  2.     ESP_LOGI("DEBUG", "We reach this point (before esp_eth_driver_install)");
  3.     vTaskDelay(100 / portTICK_PERIOD_MS); // Delay to make sure the UART Queue has time to be emptied into the Serial Monitor
  4. #endif
  5.  
  6.     ESP_GOTO_ON_FALSE(ESP_OK == esp_eth_driver_install(&eth_config_spi, &w5500_eth_handle), NULL, err, TAG, "SPI Ethernet driver install failed");
  7.  
  8. #if 1 // debug
  9.     ESP_LOGI("DEBUG", "We never reach this point (After esp_eth_driver_install)");
  10. #endif
  11.  
Here the esp_eth_driver_install(&eth_config_spi, &w5500_eth_handle) is called. This function never returns if SPI is not available or the comm line is cut.


This is the output in the Terminal:

  1. Executing action: monitor
  2. Serial port /dev/ttyUSB0
  3. Connecting...
  4.  
  5. [...]
  6.  
  7. --- esp-idf-monitor 1.5.0 on /dev/ttyUSB0 115200
  8. --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
  9. ESP-ROM:esp32s3-20210327
  10. Build:Mar 27 2021
  11. I (33) boot: ESP-IDF v5.3.1 2nd stage bootloader
  12. I (33) boot: compile time Nov  7 2024 15:29:31
  13. I (33) boot: Multicore bootloader
  14. I (36) boot: chip revision: v0.1
  15. I (40) boot.esp32s3: Boot SPI Speed : 80MHz
  16. I (45) boot.esp32s3: SPI Mode       : SLOW READ
  17. I (50) boot.esp32s3: SPI Flash Size : 8MB
  18. [...]
  19.  
  20. I (525) main_task: Started on CPU0
  21. I (535) main_task: Calling app_main()
  22.  
  23. [...]
  24.  
  25. I (695) MAIN: Starting network with following settings:
  26. Ethernet [1]
  27. Wifi [0]
  28. Access Point [1]
  29. Static IP [1]
  30. I (695) NetworkInterfaceControl: Initializing network with static IP
  31. I (705) NetworkInterfaceControl: ESP_WIFI_MODE_AP
  32. I (715) pp: pp rom version: e7ae62f
  33. I (715) net80211: net80211 rom version: e7ae62f
  34. I (735) wifi:wifi driver task: 3fcaf484, prio:23, stack:6656, core=0
  35. I (735) wifi:wifi firmware version: ccaebfa
  36. I (735) wifi:wifi certification version: v7.0
  37. I (735) wifi:config NVS flash: enabled
  38. I (735) wifi:config nano formating: disabled
  39. I (745) wifi:Init data frame dynamic rx buffer num: 32
  40. I (745) wifi:Init static rx mgmt buffer num: 5
  41. I (755) wifi:Init management short buffer num: 32
  42. I (755) wifi:Init dynamic tx buffer num: 32
  43. I (765) wifi:Init static tx FG buffer num: 2
  44. I (765) wifi:Init static rx buffer size: 1600
  45. I (765) wifi:Init static rx buffer num: 10
  46. I (775) wifi:Init dynamic rx buffer num: 32
  47. I (775) wifi_init: rx ba win: 6
  48. I (775) wifi_init: accept mbox: 6
  49. I (785) wifi_init: tcpip mbox: 32
  50. I (785) wifi_init: udp mbox: 6
  51. I (795) wifi_init: tcp mbox: 6
  52. I (795) wifi_init: tcp tx win: 5744
  53. I (795) wifi_init: tcp rx win: 5744
  54. I (805) wifi_init: tcp mss: 1440
  55. I (805) wifi_init: WiFi IRAM OP enabled
  56. I (815) wifi_init: WiFi RX IRAM OP enabled
  57. I (815) phy_init: phy_version 680,a6008b2,Jun  4 2024,16:41:10
  58. I (855) wifi:mode : softAP (34:85:18:a1:bb:b9)
  59. I (855) wifi:Total power save buffer number: 16
  60. I (855) wifi:Init max length of beacon: 752/752
  61. I (855) wifi:Init max length of beacon: 752/752
  62. I (865) wifi softAP: ap_cnct_initialize finished. SSID:ESP32 password: channel:0
  63. I (865) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.4.1
  64. I (885) NetworkInterfaceControl: Connecting to Ethernet. Opening eth_cnct_initialize
  65. I (885) Ethernet Connect Module: esp_event_loop_create_default already initialized, skipping initization
  66.  
  67.  eth_netif: 0x3fcb65ec
  68.  
  69. I (905) Ethernet Connect Module: Success to set static ip: 5100a8c0, netmask: 00ffffff, gateway: 0100a8c0
  70. I (915) Ethernet Connect Module: DNS Server: 0100a8c0
  71.  
  72.  
  73.  eth_netif: somethings not working and it is here eth_cnct_init_w5500
  74. I (1915) DEBUG: We reach this point (before eth_cnct_install_w5500_driver)
  75. I (2015) DEBUG: We reach this point (before esp_eth_driver_install)
  76.  
  77.  
  78. ESP-ROM:esp32s3-20210327
  79. Build:Mar 27 2021
  80. rst:0x8 (TG1WDT_SYS_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
  81. Saved PC:0x4037935a
  82. --- 0x4037935a: _xt_panic at /root/esp/esp-idf/components/esp_system/port/arch/xtensa/panic_handler_asm.S:32
  83.  
  84. SPIWP:0xee
  85. Octal Flash Mode Enabled
  86. For OPI Flash, Use Default Flash Boot Mode
  87. mode:SLOW_RD, clock div:1
  88. load:0x3fce2810,len:0x178c
  89. load:0x403c8700,len:0x4
  90. load:0x403c8704,len:0xcb8
  91. load:0x403cb700,len:0x2dcc
  92. entry 0x403c8914
  93. I (37) boot: ESP-IDF v5.3.1 2nd stage bootloader
  94. I (38) boot: compile time Nov  7 2024 15:29:31
  95. I (38) boot: Multicore bootloader
  96. I (41) boot: chip revision: v0.1
  97. I (45) boot.esp32s3: Boot SPI Speed : 80MHz
  98. I (49) boot.esp32s3: SPI Mode       : SLOW READ
  99. I (55) boot.esp32s3: SPI Flash Size : 8MB
  100. W (59) boot.esp32s3: PRO CPU has been reset by WDT.
  101. W (65) boot.esp32s3: APP CPU has been reset by WDT.
  102.  
As you can see, it informs us, that the Watchdogtimer on both CPUs has been triggered.

Is this known?
Can you update your software to not trigger the Watchdog and return an error, for a broken SPI Interface?

I hope this Format is fine.
Thanks in advance for taking the time to deal with my problem. :)

Greetings

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: W5500 Resets Chip without error if anything in the SPI connection is faulty.

Postby ESP_ondrej » Wed Nov 13, 2024 7:23 am

It's strange there are no W5500 errors printed in the log....

AG_OHP
Posts: 9
Joined: Mon Oct 10, 2022 7:28 am

Re: W5500 Resets Chip without error if anything in the SPI connection is faulty.

Postby AG_OHP » Fri Nov 15, 2024 4:12 pm

Thank you for this help, lol.

The reason for the error was a wrongly set Reset_pin to the W5500.
The reset pin wasn't even connected in the setup.
We set it to 35 which should not really have mattered (or at least prompted an error).
This led to the driver install function triggering the watchdog i think.

Setting the reset to any other pin makes the problem dissapear. It does not matter wether the reset pin is connected to the w5500 it just matters that it is not a forbidden pin i think.

Who is online

Users browsing this forum: No registered users and 190 guests