关于ESP32+W5500,idf ethernet basic例程,SPI spi transmit failed

thedawndawndawn
Posts: 1
Joined: Wed Aug 11, 2021 1:18 am

关于ESP32+W5500,idf ethernet basic例程,SPI spi transmit failed

Postby thedawndawndawn » Wed Aug 11, 2021 1:25 am

求助,使用idf ethernet basic例程测试W5500时,出现一下问题该怎么解决





I (364) esp_eth.netif.glue: ethernet attached to netif
I (374) eth_example: Ethernet Started
I (2374) eth_example: Ethernet Link Up
I (2374) eth_example: Ethernet HW Addr 02:00:00:12:34:56
I (2374) esp_netif_handlers: eth ip: 192.168.2.202, mask: 255.255.255.0, gw: 192.168.2.1
I (2374) eth_example: Ethernet Got IP Address
I (2384) eth_example: ~~~~~~~~~~~
I (2384) eth_example: ETHIP:192.168.2.202
I (2394) eth_example: ETHMASK:255.255.255.0
I (2394) eth_example: ETHGW:192.168.2.1
I (2404) eth_example: ~~~~~~~~~~~
E (2734) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (2734) w5500-mac: w5500_read(103): spi transmit failed
E (2744) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (2744) w5500-mac: emac_w5500_receive(555): read payload failed, len=20734, offset=156
E (8294) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8294) w5500-mac: w5500_read(103): spi transmit failed
E (8294) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8304) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8304) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8314) w5500-mac: w5500_read(103): spi transmit failed
E (8324) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8324) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8574) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8574) w5500-mac: w5500_read(103): spi transmit failed
E (8584) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8584) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8724) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8724) w5500-mac: w5500_read(103): spi transmit failed
E (8724) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8724) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8774) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8774) w5500-mac: w5500_read(103): spi transmit failed
E (8774) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8784) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8794) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8804) w5500-mac: w5500_read(103): spi transmit failed
E (8804) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8814) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8824) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8834) w5500-mac: w5500_read(103): spi transmit failed
E (8834) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8844) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8914) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8914) w5500-mac: w5500_read(103): spi transmit failed
E (8914) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8924) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8934) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8944) w5500-mac: w5500_read(103): spi transmit failed
E (8944) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8954) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8964) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (8974) w5500-mac: w5500_read(103): spi transmit failed
E (8974) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (8984) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (8994) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9004) w5500-mac: w5500_read(103): spi transmit failed
E (9004) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9014) w5500-mac: emac_w5500_receive(555): read payload failed, len=13411, offset=5318
E (9204) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9204) w5500-mac: w5500_read(103): spi transmit failed
E (9204) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9214) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9254) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9254) w5500-mac: w5500_read(103): spi transmit failed
E (9254) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9264) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9284) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9284) w5500-mac: w5500_read(103): spi transmit failed
E (9284) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9294) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9304) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9314) w5500-mac: w5500_read(103): spi transmit failed
E (9314) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9324) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9424) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9424) w5500-mac: w5500_read(103): spi transmit failed
E (9424) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9434) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9574) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9574) w5500-mac: w5500_read(103): spi transmit failed
E (9574) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9584) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9774) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9774) w5500-mac: w5500_read(103): spi transmit failed
E (9774) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9784) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9824) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9824) w5500-mac: w5500_read(103): spi transmit failed
E (9824) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9834) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9944) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9944) w5500-mac: w5500_read(103): spi transmit failed
E (9944) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (9954) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
E (9994) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (9994) w5500-mac: w5500_read(103): spi transmit failed
E (9994) w5500-mac: w5500_read_buffer(191): read RX buffer failed
E (10004) w5500-mac: emac_w5500_receive(555): read payload failed, len=28526, offset=4708
Attachments
TEMP.png
TEMP.png (79.53 KiB) Viewed 6594 times

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: 关于ESP32+W5500,idf ethernet basic例程,SPI spi transmit failed

Postby ESP_Gargamel » Wed Aug 11, 2021 2:39 am

哪个版本的 IDF?是否针对例程有修改?拿到 ip 后做了什么动作?

Ali.Akdurak
Posts: 1
Joined: Tue Jul 10, 2018 5:41 pm

Re: 关于ESP32+W5500,idf ethernet basic例程,SPI spi transmit failed

Postby Ali.Akdurak » Thu Aug 12, 2021 4:02 pm

Hey Hello,
I have the exact same problem. My ESP-IDF version is v4.3 I have applied three patches for W5500 fixes.

Code: Select all

From a94c7f3cdb59f66badc4595d0e08cd2abc8e58d9 Mon Sep 17 00:00:00 2001
From: David Cermak <cermak@espressif.com>
Date: Thu, 8 Apr 2021 10:16:08 +0200
Subject: [PATCH] esp_eth: Fix w5500 to break from potentially infinite tx loop

The issue typically happens for link-down during Tx. Added two retry levels, one before checking the sanity of the w5500 phy register and another for the Tx done itself (if the device is in the sane state)

Closes https://github.com/espressif/esp-idf/issues/6233
---
 components/esp_eth/src/esp_eth_mac_w5500.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/components/esp_eth/src/esp_eth_mac_w5500.c b/components/esp_eth/src/esp_eth_mac_w5500.c
index e713da9e74c..1f97d7fd682 100644
--- a/components/esp_eth/src/esp_eth_mac_w5500.c
+++ b/components/esp_eth/src/esp_eth_mac_w5500.c
@@ -502,6 +502,16 @@ static esp_err_t emac_w5500_set_peer_pause_ability(esp_eth_mac_t *mac, uint32_t
     return ESP_ERR_NOT_SUPPORTED;
 }
 
+static inline bool is_w5500_sane_for_rxtx(emac_w5500_t *emac)
+{
+    uint8_t phycfg;
+    /* phy is ok for rx and tx operations if bits RST and LNK are set (no link down, no reset) */
+    if (w5500_read(emac, W5500_REG_PHYCFGR, &phycfg, 1) == ESP_OK && (phycfg & 0x8001)) {
+        return true;
+    }
+   return false;
+}
+
 static esp_err_t emac_w5500_transmit(esp_eth_mac_t *mac, uint8_t *buf, uint32_t length)
 {
     esp_err_t ret = ESP_OK;
@@ -525,10 +535,14 @@ static esp_err_t emac_w5500_transmit(esp_eth_mac_t *mac, uint8_t *buf, uint32_t
     MAC_CHECK(w5500_send_command(emac, W5500_SCR_SEND, 100) == ESP_OK, "issue SEND command failed", err, ESP_FAIL);
 
     // pooling the TX done event
+    int retry = 0;
     uint8_t status = 0;
-    do {
+    while (!(status & W5500_SIR_SEND)) {
         MAC_CHECK(w5500_read(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)) == ESP_OK, "read SOCK0 IR failed", err, ESP_FAIL);
-    } while (!(status & W5500_SIR_SEND));
+        if ((retry++ > 3 && !is_w5500_sane_for_rxtx(emac)) || retry > 10) {
+            return ESP_FAIL;
+        }
+    }
     // clear the event bit
     status  = W5500_SIR_SEND;
     MAC_CHECK(w5500_write(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)) == ESP_OK, "write SOCK0 IR failed", err, ESP_FAIL);
-- 
2.30.2

Code: Select all

From fd0e023df4bf6116cacd3f816457ce8af351f950 Mon Sep 17 00:00:00 2001
From: David Cermak <cermak@espressif.com>
Date: Fri, 9 Apr 2021 20:36:01 +0200
Subject: [PATCH] esp_eth: Improve GPIO interrupt processing in w5500 driver

Increase the interrupt reassert level timing so the chances of missing
two consecutive events are minimal.
Enable only SIR_RECV interrupt event, so the SEND events are not used
for GPIO signal.

esp_eth: Recover the w5500 driver from missed io interrupt: If the GPIO interrupt is re-asserted too quickly it could be missed. If this happens the driver goes silent and never receives any data. Recover by periodic checks of the IO signal level
---
 components/esp_eth/src/esp_eth_mac_w5500.c | 13 ++++++++++---
 components/esp_eth/src/w5500.h             |  1 +
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/components/esp_eth/src/esp_eth_mac_w5500.c b/components/esp_eth/src/esp_eth_mac_w5500.c
index cc46509476d..53f35ff9cae 100644
--- a/components/esp_eth/src/esp_eth_mac_w5500.c
+++ b/components/esp_eth/src/esp_eth_mac_w5500.c
@@ -260,8 +260,11 @@ static esp_err_t w5500_setup_default(emac_w5500_t *emac)
     reg_value = W5500_SMR_MAC_RAW | W5500_SMR_MAC_FILTER;
     ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_MR(0), &reg_value, sizeof(reg_value)), err, TAG, "write SMR failed");
     /* Enable receive and send event for SOCK0 */
-    reg_value = W5500_SIR_RECV | W5500_SIR_SEND;
+    reg_value = W5500_SIR_RECV;
     ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_IMR(0), &reg_value, sizeof(reg_value)), err, TAG, "write SOCK0 IMR failed");
+    /* Set the interrupt re-assert level to maximum (~1.5ms) to lower the chances of missing it */
+    uint16_t int_level = __builtin_bswap16(0xFFFF);
+    ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_INTLEVEL, &int_level, sizeof(int_level)), err, TAG, "write INTLEVEL failed");
 
 err:
     return ret;
@@ -314,8 +317,12 @@ static void emac_w5500_task(void *arg)
     uint8_t *buffer = NULL;
     uint32_t length = 0;
     while (1) {
-        // block indefinitely until some task notifies me
-        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
+        // check if the task receives any notification
+        if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)) == 0 &&    // if no notification ...
+            gpio_get_level(emac->int_gpio_num) != 0) {               // ...and no interrupt asserted
+            continue;                                                // -> just continue to check again
+        }
+
         /* read interrupt status */
         w5500_read(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status));
         /* packet received */
diff --git a/components/esp_eth/src/w5500.h b/components/esp_eth/src/w5500.h
index 8e423796fc6..4460f7a8de5 100644
--- a/components/esp_eth/src/w5500.h
+++ b/components/esp_eth/src/w5500.h
@@ -33,6 +33,7 @@
 
 #define W5500_REG_MR        W5500_MAKE_MAP(0x0000, W5500_BSB_COM_REG) // Mode
 #define W5500_REG_MAC       W5500_MAKE_MAP(0x0009, W5500_BSB_COM_REG) // MAC Address
+#define W5500_REG_INTLEVEL  W5500_MAKE_MAP(0x0013, W5500_BSB_COM_REG) // Interrupt Level Timeout
 #define W5500_REG_IR        W5500_MAKE_MAP(0x0015, W5500_BSB_COM_REG) // Interrupt
 #define W5500_REG_IMR       W5500_MAKE_MAP(0x0016, W5500_BSB_COM_REG) // Interrupt Mask
 #define W5500_REG_SIR       W5500_MAKE_MAP(0x0017, W5500_BSB_COM_REG) // Socket Interrupt
-- 
2.30.2

last one is from https://github.com/espressif/esp-idf/co ... 8c6798f476

Code: Select all

esp_eth_mac_w5500.c 86 satır ve 111'inci satıra aşağıdaki değişiklikler uygulanacak.

    esp_err_t ret = ESP_OK;

    spi_transaction_t trans = {
        .flags = len <= 4 ? SPI_TRANS_USE_RXDATA : 0, // use direct reads for registers to prevent overwrites by 4-byte boundary writes
        .cmd = (address >> W5500_ADDR_OFFSET),
        .addr = ((address & 0xFFFF) | (W5500_ACCESS_MODE_READ << W5500_RWB_OFFSET) | W5500_SPI_OP_MODE_VDM),
        .length = 8 * len,
@@ -107,6 +108,9 @@ static esp_err_t w5500_read(emac_w5500_t *emac, uint32_t address, void *value, u
    } else {
        ret = ESP_ERR_TIMEOUT;
    }
    if ((trans.flags&SPI_TRANS_USE_RXDATA) && len <= 4) {
        memcpy(value, trans.rx_data, len);  // copy register values to output
    }
    return ret;
}


holysword
Posts: 4
Joined: Tue Nov 01, 2022 7:39 am

Re: 关于ESP32+W5500,idf ethernet basic例程,SPI spi transmit failed

Postby holysword » Tue Nov 01, 2022 7:44 am

I have the exact same problem. My ESP-IDF version is v4.4.
Can anyone solve this problem, please?

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

Re: 关于ESP32+W5500,idf ethernet basic例程,SPI spi transmit failed

Postby ESP_ondrej » Tue Nov 01, 2022 4:48 pm

The original issue should have been fixed as stated at https://github.com/espressif/esp-idf/issues/6233.

However, similar symptoms can be observed when there is an issue with SPI bus HW connection. Could you please try to decrease SPI Clock speed and check your hardware design? How is your ESP32 is connected with W5500? Is is soldered on PCB or just via jump wires? If wires are used, make sure that all wires are short as much as possible and have same length.

Who is online

Users browsing this forum: No registered users and 56 guests