From 7b72893335de05ac9810b7883510a21c1c97d422 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 21 May 2024 14:42:52 +0300 Subject: [PATCH 1/2] fix(eth): Attach ETH events at the correct place This is to ensure that stack events are called before ours, because callbacks are called in order of attaching --- libraries/Ethernet/src/ETH.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index eeda93e3201..32fb373e49f 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -163,10 +163,6 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i Network.begin(); _ethernets[_eth_index] = this; - if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) { - log_e("event_handler_instance_register for ETH_EVENT Failed!"); - return false; - } eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN; @@ -286,6 +282,11 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i return false; } + if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) { + log_e("event_handler_instance_register for ETH_EVENT Failed!"); + return false; + } + /* attach to receive events */ initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index)); @@ -550,10 +551,6 @@ bool ETHClass::beginSPI( Network.begin(); _ethernets[_eth_index] = this; - if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) { - log_e("event_handler_instance_register for ETH_EVENT Failed!"); - return false; - } // Install GPIO ISR handler to be able to service SPI Eth modules interrupts ret = gpio_install_isr_service(0); @@ -717,6 +714,11 @@ bool ETHClass::beginSPI( return false; } + if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) { + log_e("event_handler_instance_register for ETH_EVENT Failed!"); + return false; + } + /* attach to receive events */ initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index)); From e3dbce625b87f626d170d3f8d266c4cb7dd1e7fe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 18:40:42 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- libraries/Ethernet/src/ETH.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 32fb373e49f..81c9302839f 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -718,7 +718,7 @@ bool ETHClass::beginSPI( log_e("event_handler_instance_register for ETH_EVENT Failed!"); return false; } - + /* attach to receive events */ initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));