From 08b96b3ccefafee9ae77600af137b10499eb3551 Mon Sep 17 00:00:00 2001 From: whc2001 Date: Sat, 8 Jun 2024 19:06:52 -0400 Subject: [PATCH] Add ethernet PHY clock enable GPIO settings --- components/eth_interface/Kconfig.projbuild | 16 ++++++++++++++++ main/main.c | 17 ++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/components/eth_interface/Kconfig.projbuild b/components/eth_interface/Kconfig.projbuild index be5c544..f234fa7 100644 --- a/components/eth_interface/Kconfig.projbuild +++ b/components/eth_interface/Kconfig.projbuild @@ -246,4 +246,20 @@ menu "Snapclient Ethernet Configuration" help Set the second SPI Ethernet module PHY address according your board schematic. endif # SNAPCLIENT_USE_SPI_ETHERNET + + config SNAPCLIENT_ETH_CLOCK_ENABLE_GPIO + depends on SNAPCLIENT_USE_INTERNAL_ETHERNET || SNAPCLIENT_USE_SPI_ETHERNET + int "PHY Clock Enable GPIO" + default 5 + help + GPIO number to control ethernet PHY's clock. + Some PHY may have constant clock output even during reset, which might cause boot failure when using clock input + mode with GPIO0. This GPIO will be configured after boot. + + config SNAPCLIENT_ETH_CLOCK_ENABLE_ACTIVE_LOW + depends on SNAPCLIENT_USE_INTERNAL_ETHERNET || SNAPCLIENT_USE_SPI_ETHERNET + bool "PHY Clock Enable active LOW" + default false + help + Output LOW instead of HIGH on eithernet PHY clock enable pin for enable state. endmenu diff --git a/main/main.c b/main/main.c index 5d68fd7..0105496 100644 --- a/main/main.c +++ b/main/main.c @@ -2758,8 +2758,9 @@ void app_main(void) { esp_log_level_set("wifi", ESP_LOG_WARN); esp_log_level_set("wifi_init", ESP_LOG_WARN); -#if CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET || \ - CONFIG_SNAPCLIENT_USE_SPI_ETHERNET +#if (CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET || \ + CONFIG_SNAPCLIENT_USE_SPI_ETHERNET) && \ + (CONFIG_SNAPCLIENT_ETH_CLOCK_ENABLE_GPIO > -1) // clang-format off // nINT/REFCLKO Function Select Configuration Strap // • When nINTSEL is floated or pulled to @@ -2777,12 +2778,18 @@ void app_main(void) { // for MAC unit. // // clang-format on - gpio_config_t cfg = {.pin_bit_mask = BIT64(GPIO_NUM_5), - .mode = GPIO_MODE_DEF_INPUT, + ESP_LOGI(TAG, "Setting ethernet clock enable GPIO"); + gpio_config_t cfg = {.pin_bit_mask = BIT64(CONFIG_SNAPCLIENT_ETH_CLOCK_ENABLE_GPIO), + .mode = GPIO_MODE_DEF_OUTPUT, .pull_up_en = GPIO_PULLUP_DISABLE, - .pull_down_en = GPIO_PULLDOWN_ENABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, .intr_type = GPIO_INTR_DISABLE}; gpio_config(&cfg); +#if CONFIG_SNAPCLIENT_ETH_CLOCK_ENABLE_ACTIVE_LOW + gpio_set_level((gpio_num_t)CONFIG_SNAPCLIENT_ETH_CLOCK_ENABLE_GPIO, 0); +#else + gpio_set_level((gpio_num_t)CONFIG_SNAPCLIENT_ETH_CLOCK_ENABLE_GPIO, 1); +#endif #endif #if CONFIG_AUDIO_BOARD_CUSTOM && CONFIG_DAC_ADAU1961