Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

igormoo
Posts: 11
Joined: Thu Nov 28, 2024 12:54 am

Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby igormoo » Thu Dec 05, 2024 12:53 am

On Esp32-S3 I'm trying to initialize a second SPI (the first one is used for a TFT display) to run Ethernet module W5500 (similar to https://a.co/d/hL5TRAN)

The module is wired like this:

MOSI - gpio 35
MISO - gpio 37
CLK - gpio 36
SS/CS - gpio 38

when the `spi_bus_initialize` is executed - the module just crashes and reboots without any error. Any suggestions of what am I missing?

EspIDF v5.1.5
  1. #include "esp_eth.h"
  2. #include "esp_mac.h"
  3. #include "esp_netif.h"
  4.  
  5. // Define GPIO pins for Ethernet SPI
  6. #define ETHERNET_SPI_MOSI_GPIO 35 // Example GPIO for MOSI
  7. #define ETHERNET_SPI_MISO_GPIO 37 // Example GPIO for MISO
  8. #define ETHERNET_SPI_CLK_GPIO 36  // Example GPIO for SCK
  9. #define ETHERNET_SPI_CS_GPIO 38   // Example GPIO for CS
  10.  
  11. void ethernet_init() {
  12.   ESP_LOGI(TAG, "ethernet_init");
  13.   esp_err_t ret;
  14.  
  15.   // Initialize the SPI bus for SPI3
  16.   spi_bus_config_t buscfg = {
  17.     .mosi_io_num = ETHERNET_SPI_MOSI_GPIO,
  18.     .miso_io_num = ETHERNET_SPI_MISO_GPIO,
  19.     .sclk_io_num = ETHERNET_SPI_CLK_GPIO,
  20.     .quadwp_io_num = -1, // Not used
  21.     .quadhd_io_num = -1, // Not used
  22.     .max_transfer_sz = 4096,
  23.   };
  24.   ESP_LOGI(TAG, "spi_bus_initialize");
  25.   ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));  // <--- here is the crash
  26.  
  27. ...
  28. }
  29.  
I'd like to reach something similar to this thread https://esp32.com/viewtopic.php?t=36708

Thank you for the ideas

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

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby ESP_ondrej » Thu Dec 05, 2024 8:46 am

It's quite unusual to restart without any log... Is there at least backtrace? What is the exact part number of module you use?

igormoo
Posts: 11
Joined: Thu Nov 28, 2024 12:54 am

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby igormoo » Thu Dec 05, 2024 6:40 pm

Maybe the "panic" information is saying something? I don't know how to interpret this.

As you can see there is nothing specific after log output "spi_bus_initialize"

Here is how the code looks and this is what's in the trace with the highest level of VERBOSEty
  1. #define ETHERNET_SPI_MOSI_GPIO 35 // Example GPIO for MOSI
  2. #define ETHERNET_SPI_MISO_GPIO 37 // Example GPIO for MISO
  3. #define ETHERNET_SPI_CLK_GPIO 36  // Example GPIO for SCK
  4. #define ETHERNET_SPI_CS_GPIO 38   // Example GPIO for CS
  5.  
  6. void ethernet_init() {
  7.   ESP_LOGI(TAG, "ethernet_init");
  8.   esp_err_t ret;
  9.  
  10.   // Initialize the SPI bus for SPI3
  11.   spi_bus_config_t buscfg = {
  12.     .mosi_io_num = ETHERNET_SPI_MOSI_GPIO,
  13.     .miso_io_num = ETHERNET_SPI_MISO_GPIO,
  14.     .sclk_io_num = ETHERNET_SPI_CLK_GPIO,
  15.     .quadwp_io_num = -1, // Not used
  16.     .quadhd_io_num = -1, // Not used
  17.     .max_transfer_sz = 4096,
  18.   };
  19.   ESP_LOGI(TAG, "spi_bus_initialize");
  20.   // ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
  21.   esp_err_t err = spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO);
  22.   if (err != ESP_OK) {
  23.     ESP_LOGE("SPI", "Failed to initialize bus: %s", esp_err_to_name(err));
  24.     return;
  25.   }
  26.   ESP_LOGI(TAG, "spi_bus_initialize complete");
  27.   ...
  28. }

Code: Select all

I (1929) main: IDF version: v5.1.5-dirty
I (1934) main: ESP-IDF Version: 5.1.5

I (1938) Ethernet: ethernet_init
I (1942) Ethernet: spi_bus_initialize
D (1947) gdma: new group (0) at 0x3c070b80
D (1951) gdma: new pair (0,0) at 0x3c070bc4
D (1955) gdma: new tx channel (0,0) at 0x3c070b4c
D (1960) gdma: new rx channel (0,0) at 0x3c070be4
D (1965) spi: SPI3 use gpio matrix.
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)
Saved PC:0x40375b61
--- 0x40375b61: panicHandler at /Users/igor/esp/v5.1.5/esp-idf/components/esp_system/port/panic_handler.c:217

SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fce3810,len:0x1a2c
load:0x403c9700,len:0x4
load:0x403c9704,len:0x1088
load:0x403cc700,len:0x2fc8
SHA-256 comparison failed:
Calculated: 199fc0fcb8b95d8ca3a70b2bf648cf011b7b8936d0c7f11a9f79f9553fa7fe37
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway...
entry 0x403c9994

FrankJensen
Posts: 55
Joined: Sun Mar 10, 2024 9:34 pm

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby FrankJensen » Thu Dec 05, 2024 8:38 pm

Does it compile and run without the SPI initializing? I think this looks strange, no matter if your code is good or bad:

Code: Select all

SHA-256 comparison failed:
Calculated: 199fc0fcb8b95d8ca3a70b2bf648cf011b7b8936d0c7f11a9f79f9553fa7fe37
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway...
entry 0x403c9994

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

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby ESP_ondrej » Fri Dec 06, 2024 7:44 am

You didn't answer to my question, what is the exact part number of module you use, please? The reason I'm asking is:
" For modules with Octal SPI PSRAM, i.e., modules embedded with ESP32-S3R8 or ESP32-S3R16V,
pins IO35, IO36, and IO37 are connected to the Octal SPI PSRAM and are not available for other
uses."

igormoo
Posts: 11
Joined: Thu Nov 28, 2024 12:54 am

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby igormoo » Tue Dec 10, 2024 3:33 pm

Thank you for pointing this out. My apologies, I thought you were referring to the ETH module, not to ESP32. I'm using "ESP32-S3-DevKitC-1-N32R8V Development Board".

Maybe I'm a bit biased because I've tested this hypothesis previously with a different pin layout and got the same error. Here is one of the setups I've tried:
  1. #define ETHERNET_SPI_MOSI_GPIO 23 // Example GPIO for MOSI
  2. #define ETHERNET_SPI_MISO_GPIO 19 // Example GPIO for MISO
  3. #define ETHERNET_SPI_CLK_GPIO 18  // Example GPIO for SCK
  4. #define ETHERNET_SPI_CS_GPIO 5   // Example GPIO for CS
What may be a suggested pin setup for a second SPI on this module? Does anyone have it working?

I've found an interesting thread that may be related to this topic: https://github.com/espressif/arduino-esp32/pull/7163

Am I overthinking this?

thanks

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

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby ESP_ondrej » Thu Dec 12, 2024 7:42 am

Code: Select all

#define ETHERNET_SPI_MOSI_GPIO 23 // Example GPIO for MOSI
Such GPIO pin number is not available https://docs.espressif.com/projects/esp ... ng-started

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

Re: Esp32-S3 crashes when a second SPI is initialized for Ethernet module W5500

Postby ESP_ondrej » Thu Dec 12, 2024 8:04 am

Also see https://www.espressif.com/sites/default ... eet_en.pdf, Section "2.3 IO Pins" to consult usage restrictions which may apply to certain GPIO.

Who is online

Users browsing this forum: Google [Bot], JohnnyZ and 93 guests