From 896a07e5d66b47d93f6a42cb9320e090c02ce972 Mon Sep 17 00:00:00 2001 From: Jackson Ming Hu Date: Sat, 6 May 2023 23:33:39 +1000 Subject: [PATCH] w5500: rework version check to avoid a false alarm on fault detection See: https://github.com/espressif/esp-idf/issues/11331 --- components/esp_eth/src/esp_eth_mac_w5500.c | 18 +++++++++++++++--- 1 file changed, 15 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 e590d7df50..7a7708d0ca 100644 --- a/components/esp_eth/src/esp_eth_mac_w5500.c +++ b/components/esp_eth/src/esp_eth_mac_w5500.c @@ -229,10 +229,22 @@ static esp_err_t w5500_verify_id(emac_w5500_t *emac) { esp_err_t ret = ESP_OK; uint8_t version = 0; - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_VERSIONR, &version, sizeof(version)), err, TAG, "read VERSIONR failed"); - // W5500 doesn't have chip ID, we check the version number instead - ESP_GOTO_ON_FALSE(version == W5500_CHIP_VERSION, ESP_ERR_INVALID_VERSION, err, TAG, "invalid chip version, expected 0x%x, actual 0x%x", W5500_CHIP_VERSION, version); + // W5500 doesn't have chip ID, we check the version number instead + // The version number may be polled multiple times since it was observed that + // some W5500 units may return version 0 when it is read right after the reset + ESP_LOGD(TAG, "Waiting W5500 to start & verify version..."); + uint32_t to = 0; + for (to = 0; to < emac->sw_reset_timeout_ms / 10; to++) { + ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_VERSIONR, &version, sizeof(version)), err, TAG, "read VERSIONR failed"); + if (version == W5500_CHIP_VERSION) { + return ESP_OK; + } + vTaskDelay(pdMS_TO_TICKS(10)); + } + + ESP_LOGE(TAG, "W5500 version mismatched, expected 0x%02x, got 0x%02x", W5500_CHIP_VERSION, version); + return ESP_ERR_INVALID_VERSION; err: return ret; }