Skip to content

Commit 7b72893

Browse files
committed
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
1 parent 50ef6f4 commit 7b72893

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Diff for: libraries/Ethernet/src/ETH.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
163163

164164
Network.begin();
165165
_ethernets[_eth_index] = this;
166-
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
167-
log_e("event_handler_instance_register for ETH_EVENT Failed!");
168-
return false;
169-
}
170166

171167
eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
172168
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
286282
return false;
287283
}
288284

285+
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
286+
log_e("event_handler_instance_register for ETH_EVENT Failed!");
287+
return false;
288+
}
289+
289290
/* attach to receive events */
290291
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));
291292

@@ -550,10 +551,6 @@ bool ETHClass::beginSPI(
550551

551552
Network.begin();
552553
_ethernets[_eth_index] = this;
553-
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
554-
log_e("event_handler_instance_register for ETH_EVENT Failed!");
555-
return false;
556-
}
557554

558555
// Install GPIO ISR handler to be able to service SPI Eth modules interrupts
559556
ret = gpio_install_isr_service(0);
@@ -717,6 +714,11 @@ bool ETHClass::beginSPI(
717714
return false;
718715
}
719716

717+
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
718+
log_e("event_handler_instance_register for ETH_EVENT Failed!");
719+
return false;
720+
}
721+
720722
/* attach to receive events */
721723
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));
722724

0 commit comments

Comments
 (0)