@@ -119,7 +119,7 @@ void ETHClass::_onEthEvent(int32_t event_id, void *event_data) {
119119}
120120
121121ETHClass::ETHClass (uint8_t eth_index)
122- : _eth_handle(NULL ), _eth_index(eth_index), _phy_type(ETH_PHY_MAX), _glue_handle(NULL )
122+ : _eth_handle(NULL ), _eth_index(eth_index), _phy_type(ETH_PHY_MAX), _glue_handle(NULL ), _mac( NULL ), _phy( NULL )
123123#if ETH_SPI_SUPPORTS_CUSTOM
124124 ,
125125 _spi (NULL )
@@ -587,8 +587,6 @@ bool ETHClass::beginSPI(
587587 spi_devcfg.spics_io_num = _pin_cs;
588588 spi_devcfg.queue_size = 20 ;
589589
590- esp_eth_mac_t *mac = NULL ;
591- esp_eth_phy_t *phy = NULL ;
592590#if CONFIG_ETH_SPI_ETHERNET_W5500
593591 if (type == ETH_PHY_W5500) {
594592 eth_w5500_config_t mac_config = ETH_W5500_DEFAULT_CONFIG (spi_host, &spi_devcfg);
@@ -607,8 +605,8 @@ bool ETHClass::beginSPI(
607605 mac_config.custom_spi_driver .write = _eth_spi_write;
608606 }
609607#endif
610- mac = esp_eth_mac_new_w5500 (&mac_config, ð_mac_config);
611- phy = esp_eth_phy_new_w5500 (&phy_config);
608+ _mac = esp_eth_mac_new_w5500 (&mac_config, ð_mac_config);
609+ _phy = esp_eth_phy_new_w5500 (&phy_config);
612610 } else
613611#endif
614612#if CONFIG_ETH_SPI_ETHERNET_DM9051
@@ -624,8 +622,8 @@ bool ETHClass::beginSPI(
624622 mac_config.custom_spi_driver .write = _eth_spi_write;
625623 }
626624#endif
627- mac = esp_eth_mac_new_dm9051 (&mac_config, ð_mac_config);
628- phy = esp_eth_phy_new_dm9051 (&phy_config);
625+ _mac = esp_eth_mac_new_dm9051 (&mac_config, ð_mac_config);
626+ _phy = esp_eth_phy_new_dm9051 (&phy_config);
629627 } else
630628#endif
631629#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
@@ -641,8 +639,8 @@ bool ETHClass::beginSPI(
641639 mac_config.custom_spi_driver .write = _eth_spi_write;
642640 }
643641#endif
644- mac = esp_eth_mac_new_ksz8851snl (&mac_config, ð_mac_config);
645- phy = esp_eth_phy_new_ksz8851snl (&phy_config);
642+ _mac = esp_eth_mac_new_ksz8851snl (&mac_config, ð_mac_config);
643+ _phy = esp_eth_phy_new_ksz8851snl (&phy_config);
646644 } else
647645#endif
648646 {
@@ -651,7 +649,7 @@ bool ETHClass::beginSPI(
651649 }
652650
653651 // Init Ethernet driver to default and install it
654- esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG (mac, phy );
652+ esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG (_mac, _phy );
655653 ret = esp_eth_driver_install (ð_config, &_eth_handle);
656654 if (ret != ESP_OK) {
657655 log_e (" SPI Ethernet driver install failed: %d" , ret);
@@ -841,6 +839,16 @@ void ETHClass::end(void) {
841839 return ;
842840 }
843841 _eth_handle = NULL ;
842+ // delete mac
843+ if (_mac != NULL ) {
844+ _mac->del (_mac);
845+ _mac = NULL ;
846+ }
847+ // delete phy
848+ if (_phy != NULL ) {
849+ _phy->del (_phy);
850+ _phy = NULL ;
851+ }
844852 }
845853
846854 if (_eth_ev_instance != NULL ) {
0 commit comments