Skip to content

fix(eth): Attach ETH events at the correct place #9658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions libraries/Ethernet/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down