I'm not being able to find the root cause of this and how to fix it.
Following are the serial logs and ethernet initialization function.
Serial Logs
I (2864) enc28j60: revision: 6
I (2874) esp_eth.netif.netif_glue: 8c:4b:14:7a:3e:64
I (2874) esp_eth.netif.netif_glue: ethernet attached to netif
I (2874) enc28j60: working in 10Mbps
I (2884) enc28j60: working in full duplex
I (2884) ETHERNET: Ethernet Link Up
W (2894) ETHERNET: [ ETHERNET TRANSMISSION MODE ] : [ FULL DUPLEX ]
I (2894) ETHERNET: Ethernet HW Addr 8c:4b:14:7a:3e:64
I (2904) ETHERNET: [ ETHERNET TRANSMISSION MODE SET TO FULL DUPLEX ]
E (2904) esp_netif_lwip: dhcp client start failed
I (2914) ETHERNET: Ethernet Started
I (2924) ETHERNET: ETHERNET Started successfully
W (12924) ETHERNET: DHCPC (state=0)
I (12924) ETHERNET: DHCP client status : ESP_OK
Ethernet init
Code: Select all
ethernet_events = xEventGroupCreate();
esp_netif_init();
esp_event_loop_create_default();
// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler_for_ethernet, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, event_handler_for_ethernet, NULL));
esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
eth_netif = esp_netif_new(&netif_cfg);
spi_bus_config_t buscfg = {
.miso_io_num = ETH_SPI_MISO,
.mosi_io_num = ETH_SPI_MOSI,
.sclk_io_num = ETH_SPI_SCK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
};
ESP_ERROR_CHECK(spi_bus_initialize(ETH_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO));
/* ENC28J60 ethernet driver is based on spi driver */
spi_device_interface_config_t devcfg = {
.command_bits = 3,
.address_bits = 5,
.mode = 0,
.clock_speed_hz = ETH_SPI_CLOCK_MHZ * 1000 * 1000,
.spics_io_num = ETH_CS_GPIO,
.queue_size = 20,
.cs_ena_posttrans = enc28j60_cal_spi_cs_hold_time(ETH_SPI_CLOCK_MHZ),
};
spi_device_handle_t spi_handle = NULL;
ESP_ERROR_CHECK(spi_bus_add_device(ETH_SPI_HOST, &devcfg, &spi_handle));
eth_enc28j60_config_t enc28j60_config = ETH_ENC28J60_DEFAULT_CONFIG(spi_handle);
enc28j60_config.int_gpio_num = ETH_INT_GPIO;
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.smi_mdc_gpio_num = -1; // ENC28J60 doesn't have SMI interface
mac_config.smi_mdio_gpio_num = -1;
esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config);
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.autonego_timeout_ms = 0; // ENC28J60 doesn't support auto-negotiation
phy_config.reset_gpio_num = -1; // ENC28J60 doesn't have a pin to reset internal PHY
esp_eth_phy_t *phy = esp_eth_phy_new_enc28j60(&phy_config);
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy);
esp_eth_handle_t eth_handle = NULL;
ESP_ERROR_CHECK(esp_eth_driver_install(ð_config, ð_handle));
/* ENC28J60 doesn't burn any factory MAC address, we need to set it manually.
02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your control.
*/
mac->set_addr(mac, (uint8_t[]){
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]});
// ENC28J60 Errata #1 checkETH_SPI_CLOCK_MHZ
if (emac_enc28j60_get_chip_info(mac) < ENC28J60_REV_B5 && ETH_SPI_CLOCK_MHZ < 8)
{
ESP_LOGE(TAG, "SPI frequency must be at least 8 MHz for chip revision less than 5");
ESP_ERROR_CHECK(ESP_FAIL);
}
// Stop DHCP --------------------------------------------------------------------------------------------------
/* attach Ethernet driver to TCP/IP stack */
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
/* It is recommended to use ENC28J60 in Full Duplex mode since multiple errata exist to the Half Duplex mode */
// if CONFIG_EXAMPLE_ENC28J60_DUPLEX_FULL
/* Set duplex needs to be called after esp_eth_start since the driver is started with auto-negotiation by default */
err = enc28j60_set_phy_duplex(phy, ETH_DUPLEX_FULL);
if (err == ESP_OK)
{
ESP_LOGI(TAG, "[ ETHERNET TRANSMISSION MODE SET TO FULL DUPLEX ]");
}
// #endif
/* start Ethernet driver state machine */
err = esp_eth_start(eth_handle);
if (err == ESP_OK)
ESP_LOGI(TAG, "ETHERNET Started successfully");
else
ESP_LOGE(TAG, "ETHERNET Start failed");
xEventGroupWaitBits(ethernet_events, CONNECTED_GOT_IP | DISCONNECTED, pdTRUE, pdFALSE, pdMS_TO_TICKS(10000));
esp_netif_dhcp_status_t status;
esp_netif_dhcpc_get_status(eth_netif, &status);
ESP_LOGW(TAG, " DHCPC (state=%u)", status);
if (status == 0x0)
{
esp_err_t err_dhcp = esp_netif_dhcpc_start(eth_netif);
ESP_LOGI(TAG, "DHCP client status : %s", esp_err_to_name(err_dhcp));
}
Please help out.
Thank you.