From 7cb91c19cd7017c69539fb13e4e9ccd60b75151f Mon Sep 17 00:00:00 2001 From: Bogdan Kolendovskyy Date: Wed, 7 Feb 2024 11:24:17 +0100 Subject: [PATCH] fix(esp_eth): ip101-specific reset_hw to match reset timings from datasheet IP101 requires 10ms reset assertion time and 10ms post-reset delay to properly initialize. --- components/esp_eth/src/esp_eth_phy_802_3.c | 8 ++++++-- components/esp_eth/src/esp_eth_phy_ip101.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/components/esp_eth/src/esp_eth_phy_802_3.c b/components/esp_eth/src/esp_eth_phy_802_3.c index d8db761433..3e354915da 100644 --- a/components/esp_eth/src/esp_eth_phy_802_3.c +++ b/components/esp_eth/src/esp_eth_phy_802_3.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -366,7 +366,11 @@ esp_err_t esp_eth_phy_802_3_reset_hw(phy_802_3_t *phy_802_3, uint32_t reset_asse esp_rom_gpio_pad_select_gpio(phy_802_3->reset_gpio_num); gpio_set_direction(phy_802_3->reset_gpio_num, GPIO_MODE_OUTPUT); gpio_set_level(phy_802_3->reset_gpio_num, 0); - esp_rom_delay_us(reset_assert_us); + if (reset_assert_us < 10000) { + esp_rom_delay_us(reset_assert_us); + } else { + vTaskDelay(pdMS_TO_TICKS(reset_assert_us/1000)); + } gpio_set_level(phy_802_3->reset_gpio_num, 1); } return ESP_OK; diff --git a/components/esp_eth/src/esp_eth_phy_ip101.c b/components/esp_eth/src/esp_eth_phy_ip101.c index 903ca066d6..a32a3bffb6 100644 --- a/components/esp_eth/src/esp_eth_phy_ip101.c +++ b/components/esp_eth/src/esp_eth_phy_ip101.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,10 +8,15 @@ #include #include "esp_log.h" #include "esp_check.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" #include "esp_eth_phy_802_3.h" static const char *TAG = "ip101"; +#define IP101_PHY_RESET_ASSERTION_TIME_US 10000 +#define IP101_PHY_POST_RESET_INIT_TIME_MS 10 + /***************Vendor Specific Register***************/ /** @@ -166,6 +171,14 @@ err: return ret; } +static esp_err_t ip101_reset_hw(esp_eth_phy_t *phy) +{ + phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy); + esp_err_t ret = esp_eth_phy_802_3_reset_hw(phy_802_3, IP101_PHY_RESET_ASSERTION_TIME_US); + vTaskDelay(pdMS_TO_TICKS(IP101_PHY_POST_RESET_INIT_TIME_MS)); + return ret; +} + static esp_err_t ip101_init(esp_eth_phy_t *phy) { esp_err_t ret = ESP_OK; @@ -197,6 +210,7 @@ esp_eth_phy_t *esp_eth_phy_new_ip101(const eth_phy_config_t *config) // redefine functions which need to be customized for sake of IP101 ip101->phy_802_3.parent.init = ip101_init; ip101->phy_802_3.parent.get_link = ip101_get_link; + ip101->phy_802_3.parent.reset_hw = ip101_reset_hw; return &ip101->phy_802_3.parent; err: