eth2ap not able to connect to internet

Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

eth2ap not able to connect to internet

Postby Palonso » Tue Oct 26, 2021 9:24 pm

Hi,

I have an adapted version of the eth2ap example code so it bridges with the ENC28J60 to WiFi, the device connects successfully to the router through Ethernet and my PC connects to the ESP-WROOM correctly, but after a while it disconnects without reason. My phone says it didn't get the IP address, but that's not done by the ESP-WROOM, right?

Here is the log:

Code: Select all

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6984
load:0x40078000,len:14292
load:0x40080400,len:3688
0x40080400: _init at ??:?

entry 0x40080678
I (27) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (27) boot: compile time 12:14:23
I (27) boot: chip revision: 3
I (30) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed      : 40MHz
I (42) boot.esp32: SPI Mode       : DIO
I (47) boot.esp32: SPI Flash Size : 16MB
I (51) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (68) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (75) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (83) boot:  2 factory          factory app      00 00 00010000 00100000
I (90) boot: End of partition table
I (94) boot_comm: chip revision: 3, min. application chip revision: 0
I (101) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1b058h (110680) map
I (152) esp_image: segment 1: paddr=0002b080 vaddr=3ffb0000 size=044f8h ( 17656) load
I (159) esp_image: segment 2: paddr=0002f580 vaddr=40080000 size=00a98h (  2712) load
I (160) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=78dd0h (495056) map
I (353) esp_image: segment 4: paddr=000a8df8 vaddr=40080a98 size=164e8h ( 91368) load
I (392) esp_image: segment 5: paddr=000bf2e8 vaddr=50000000 size=00010h (    16) load
I (405) boot: Loaded app from partition at offset 0x10000
I (405) boot: Disabling RNG early entropy source...
I (416) cpu_start: Pro cpu up.
I (416) cpu_start: Starting app cpu, entry point is 0x400813f4
0x400813f4: call_start_cpu1 at /home/pablo/esp/esp-idf43/components/esp_system/port/cpu_start.c:141

I (0) cpu_start: App cpu up.
I (431) cpu_start: Pro cpu start user code
I (431) cpu_start: cpu freq: 160000000
I (431) cpu_start: Application information:
I (435) cpu_start: Project name:     ethernet_module
I (441) cpu_start: App version:      v3.2.02-141-g80630d0-dirty
I (447) cpu_start: Compile time:     Oct 26 2021 16:03:51
I (453) cpu_start: ELF file SHA256:  3cb6a8b8656718c7...
I (459) cpu_start: ESP-IDF:          v4.3-dirty
I (465) heap_init: Initializing. RAM available for dynamic allocation:
I (472) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (478) heap_init: At 3FFB8180 len 00027E80 (159 KiB): DRAM
I (484) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (490) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (497) heap_init: At 40096F80 len 00009080 (36 KiB): IRAM
I (504) spi_flash: detected chip: generic
I (508) spi_flash: flash io: dio
I (513) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (558) ethernet: revision: 6
I (568) esp_eth.netif.glue: 02:00:00:12:34:56
I (568) esp_eth.netif.glue: ethernet attached to netif
I (578) ethernet: Ethernet Started
I (588) wifi:wifi driver task: 3ffb9d10, prio:23, stack:6656, core=0
I (588) system_api: Base MAC address is not set
I (588) system_api: read default base MAC address from EFUSE
I (598) wifi:wifi firmware version: c7d0450
I (598) wifi:wifi certification version: v7.0
I (598) wifi:config NVS flash: enabled
I (608) wifi:config nano formating: disabled
I (608) wifi:Init data frame dynamic rx buffer num: 32
I (608) wifi:Init management frame dynamic rx buffer num: 32
I (618) wifi:Init management short buffer num: 32
I (618) wifi:Init dynamic tx buffer num: 32
I (628) wifi:Init static rx buffer size: 1600
I (628) wifi:Init static rx buffer num: 10
I (638) wifi:Init dynamic rx buffer num: 32
I (638) wifi_init: rx ba win: 6
I (638) wifi_init: tcpip mbox: 32
I (648) wifi_init: udp mbox: 6
I (648) wifi_init: tcp mbox: 6
I (648) wifi_init: tcp tx win: 5744
I (658) wifi_init: tcp rx win: 5744
I (658) wifi_init: tcp mss: 1440
I (668) wifi_init: WiFi IRAM OP enabled
I (668) wifi_init: WiFi RX IRAM OP enabled
I (2578) ethernet: working in 10Mbps
I (2578) ethernet: working in half duplex
I (2578) ethernet: Ethernet Link Up
I (2578) ethernet: Ethernet HW Addr 02:00:00:12:34:56
I (2578) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
W (2588) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (2768) wifi:mode : softAP (02:00:00:12:34:56)
I (2768) wifi:Total power save buffer number: 16
I (2768) wifi:Init max length of beacon: 752/752
I (2778) wifi:Init max length of beacon: 752/752
I (5558) esp_netif_handlers: eth ip: 192.168.86.96, mask: 255.255.255.0, gw: 192.168.86.1
I (5558) ethernet: Ethernet Got IP Address
I (5558) ethernet: ~~~~~~~~~~~
E (5558) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
I (5558) ethernet: ETHIP:192.168.86.96
I (5578) ethernet: ETHMASK:255.255.255.0
I (5578) ethernet: ETHGW:192.168.86.1
I (5588) ethernet: ~~~~~~~~~~~
I (31128) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (31128) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (31158) ethernet: Wi-Fi AP got a station connected
I (76818) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffbad1c
I (76818) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (76828) ethernet: Wi-Fi AP got a station disconnected
I (84608) wifi:new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (84608) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (84628) ethernet: Wi-Fi AP got a station connected
I (129818) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffbad1c
I (129818) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (129828) ethernet: Wi-Fi AP got a station disconnected
I (251638) wifi:new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (251638) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (251648) ethernet: Wi-Fi AP got a station connected
I (296808) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffbad1c
I (296818) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (296818) ethernet: Wi-Fi AP got a station disconnected
Ethernet handles, WiFi handles and flow control are initialized and should be running, so I'm not sure what's wrong. Any idea?

Best regards,
P

Here I leave the code I'm using:

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_eth.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "driver/uart.h"

#include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_private/wifi.h"

const char *TAG = "ethernet";

esp_eth_handle_t eth_handle = NULL;
QueueHandle_t flow_control_queue = NULL;
bool s_sta_is_connected = false;
bool s_ethernet_is_connected = false;

// Forward packets from Wi-Fi to Ethernet
esp_err_t pkt_wifi2eth(void *buffer, uint16_t len, void *eb)
{
    if (s_ethernet_is_connected) {
        if (esp_eth_transmit(eth_handle, buffer, len) != ESP_OK) {
            ESP_LOGE(TAG, "Ethernet send packet failed");
        }
    }
    ESP_LOG_BUFFER_HEX("output", buffer,len);
    esp_wifi_internal_free_rx_buffer(eb);
    return ESP_OK;
}

// Forward packets from Ethernet to Wi-Fi
// Note that, Ethernet works faster than Wi-Fi on ESP32,
// so we need to add an extra queue to balance their speed difference.
esp_err_t pkt_eth2wifi(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t len, void* priv)
{
    esp_err_t ret = ESP_OK;
    flow_control_msg_t msg = {
        .packet = buffer,
        .length = len
    };
    if (xQueueSend(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) != pdTRUE) {
        ESP_LOGE(TAG, "send flow control message failed or timeout");
        free(buffer);
        ret = ESP_FAIL;
    }
    ESP_LOG_BUFFER_HEX("input", buffer,len);
    return ret;
}

// This task will fetch the packet from the queue, and then send out through Wi-Fi.
// Wi-Fi handles packets slower than Ethernet, we might add some delay between each transmitting.
void eth2wifi_flow_control_task(void *args)
{
    flow_control_msg_t msg;
    int res = 0;
    uint32_t timeout = 0;
    while (1) {
        if (xQueueReceive(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) == pdTRUE) {
            timeout = 0;
            if (s_sta_is_connected && msg.length) {
                do {
                    vTaskDelay(pdMS_TO_TICKS(timeout));
                    timeout += 2;
                    res = esp_wifi_internal_tx(ESP_IF_WIFI_AP, msg.packet, msg.length);
                } while (res && timeout < FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS);
                if (res != ESP_OK) {
                    ESP_LOGE(TAG, "WiFi send packet failed: %d", res);
                }
            }
            free(msg.packet);
        }
    }
    vTaskDelete(NULL);
}


/** Event handler for Ethernet events */
void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    uint8_t mac_addr[6] = {0};
    /* we can get the ethernet driver handle from event data */
    esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;

    switch (event_id) 
    {
        case ETHERNET_EVENT_CONNECTED:
            esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);    //Obtengo direccion MAC
            ESP_LOGI(TAG, "Ethernet Link Up");
            s_ethernet_is_connected = true;
            ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
            esp_wifi_set_mac(WIFI_IF_AP, mac_addr);
            ESP_ERROR_CHECK(esp_wifi_start());
            break;
        case ETHERNET_EVENT_DISCONNECTED:
            ESP_LOGI(TAG, "Ethernet Link Down");
            s_ethernet_is_connected = false;
            ESP_ERROR_CHECK(esp_wifi_stop());
            break;
        case ETHERNET_EVENT_START:
            ESP_LOGI(TAG, "Ethernet Started");
            break;
        case ETHERNET_EVENT_STOP:
            ESP_LOGI(TAG, "Ethernet Stopped");
            break;
        default:
            break;
    }
}

// Event handler for Wi-Fi
void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    uint8_t s_con_cnt = 0;
    switch (event_id) 
    {
        case WIFI_EVENT_AP_STACONNECTED:
            ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
            if (!s_con_cnt)
            {
                s_sta_is_connected = true;
                esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, pkt_wifi2eth);
            }
            s_con_cnt++;
            break;
        case WIFI_EVENT_AP_STADISCONNECTED:
            ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
            s_con_cnt--;
            if (!s_con_cnt)
            {
                s_sta_is_connected = false;
                esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL);
            }
            break;
        default:
            break;
    }
}

/** Event handler for IP_EVENT_ETH_GOT_IP */
void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
    const esp_netif_ip_info_t *ip_info = &event->ip_info;

    ESP_LOGI(TAG, "Ethernet Got IP Address");
    ESP_LOGI(TAG, "~~~~~~~~~~~");
    ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip));
    ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask));
    ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw));
    ESP_LOGI(TAG, "~~~~~~~~~~~");
}

void initialize_ethernet(void)
{
    ESP_ERROR_CHECK(gpio_install_isr_service(0));
    // Initialize TCP/IP network interface (should be called only once in application)
    ESP_ERROR_CHECK(esp_netif_init());
    esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
    esp_netif_t *eth_netif = esp_netif_new(&netif_cfg);
    // Set default handlers to process TCP/IP stuffs
    ESP_ERROR_CHECK(esp_eth_set_default_handlers(eth_netif));
    // Register user defined event handers
    ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

    /* SPI Bus configuration */
    spi_bus_config_t buscfg = {
        .miso_io_num = GPIO_NUM_25,
        .mosi_io_num = GPIO_NUM_23,
        .sclk_io_num = GPIO_NUM_19,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
    };
    ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, 1));

    /* 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 = SPI_CLOCK_6MHZ,
        .spics_io_num = GPIO_NUM_22,
        .queue_size = 20,
        // .cs_ena_posttrans = enc28j60_cal_spi_cs_hold_time(6)
    };
    spi_device_handle_t spi_handle = NULL;
    ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg, &spi_handle));

    /* enc28j60 ethernet driver is based on spi driver */
    eth_enc28j60_config_t enc28j60_config = ETH_ENC28J60_DEFAULT_CONFIG(spi_handle);
    enc28j60_config.int_gpio_num = GPIO_NUM_4;
    
    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.phy_addr = 0;
    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);
    eth_config.stack_input = pkt_eth2wifi;
    ESP_ERROR_CHECK(esp_eth_driver_install(&eth_config, &eth_handle));
    esp_eth_ioctl(eth_handle, ETH_CMD_S_PROMISCUOUS, (void *)true);

    /*  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[]) {
        0x02, 0x00, 0x00, 0x12, 0x34, 0x56
    });

    /* attach Ethernet driver to TCP/IP stack */
    ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
    /* start Ethernet driver state machine */
    ESP_ERROR_CHECK(esp_eth_start(eth_handle));
}

void initialize_wifi(void)
{
    // ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL));
    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL));
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));
    // ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
    wifi_config_t wifi_config = {
        .ap = {
            .ssid = "TEST_SSID",
            .ssid_len = strlen("TEST_SSID"),
            .password = "SSID_TEST",
            .max_connection = 5,
            .authmode = WIFI_AUTH_WPA_WPA2_PSK,
            .channel = 1 // default: channel 1
        },
    };
    if (strlen("CONFIG_EXAMPLE_WIFI_PASSWORD") == 0) {
        wifi_config.ap.authmode = WIFI_AUTH_OPEN;
    }
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
    ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
}

esp_err_t initialize_flow_control(void)
{
    flow_control_queue = xQueueCreate(FLOW_CONTROL_QUEUE_LENGTH, sizeof(flow_control_msg_t));
    if (!flow_control_queue) {
        ESP_LOGE(TAG, "create flow control queue failed");
        return ESP_FAIL;
    }
    BaseType_t ret = xTaskCreate(eth2wifi_flow_control_task, "flow_ctl", 2048, NULL, (tskIDLE_PRIORITY + 2), NULL);
    if (ret != pdTRUE) {
        ESP_LOGE(TAG, "create flow control task failed");
        return ESP_FAIL;
    }
    return ESP_OK;
}

void app_main(void)
{
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    ESP_ERROR_CHECK(initialize_flow_control());

    initialize_ethernet();
    initialize_wifi();
}
UPDATE:
I was trying to find the problem in my code and got the next lof output (hope works for somebody):

Code: Select all

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6984
load:0x40078000,len:14292
load:0x40080400,len:3688
0x40080400: _init at ??:?

entry 0x40080678
I (27) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (27) boot: compile time 12:14:23
I (27) boot: chip revision: 3
I (30) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed      : 40MHz
I (42) boot.esp32: SPI Mode       : DIO
I (47) boot.esp32: SPI Flash Size : 16MB
I (51) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (68) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (75) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (83) boot:  2 factory          factory app      00 00 00010000 00100000
I (90) boot: End of partition table
I (94) boot_comm: chip revision: 3, min. application chip revision: 0
I (101) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1b3d0h (111568) map
I (152) esp_image: segment 1: paddr=0002b3f8 vaddr=3ffb0000 size=04478h ( 17528) load
I (159) esp_image: segment 2: paddr=0002f878 vaddr=40080000 size=007a0h (  1952) load
I (160) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=797b0h (497584) map
I (354) esp_image: segment 4: paddr=000a97d8 vaddr=400807a0 size=167e0h ( 92128) load
I (393) esp_image: segment 5: paddr=000bffc0 vaddr=50000000 size=00010h (    16) load
I (406) boot: Loaded app from partition at offset 0x10000
I (406) boot: Disabling RNG early entropy source...
I (418) cpu_start: Pro cpu up.
I (418) cpu_start: Starting app cpu, entry point is 0x400813f4
0x400813f4: call_start_cpu1 at /home/pablo/esp/esp-idf43/components/esp_system/port/cpu_start.c:141

I (0) cpu_start: App cpu up.
I (432) cpu_start: Pro cpu start user code
I (432) cpu_start: cpu freq: 160000000
I (432) cpu_start: Application information:
I (437) cpu_start: Project name:     ethernet_module
I (442) cpu_start: App version:      v3.2.02-146-gf31edc4-dirty
I (449) cpu_start: Compile time:     Oct 27 2021 17:41:55
I (455) cpu_start: ELF file SHA256:  ba908850a01daa73...
I (461) cpu_start: ESP-IDF:          v4.3-dirty
I (466) heap_init: Initializing. RAM available for dynamic allocation:
I (474) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (480) heap_init: At 3FFB8130 len 00027ED0 (159 KiB): DRAM
I (486) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (492) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (499) heap_init: At 40096F80 len 00009080 (36 KiB): IRAM
I (506) spi_flash: detected chip: generic
I (510) spi_flash: flash io: dio
I (515) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (582) ethernet: revision: 6
I (602) esp_eth.netif.glue: 02:04:a3:12:34:56
I (602) esp_eth.netif.glue: ethernet attached to netif
I (612) ethernet: Ethernet Started
I (622) wifi:wifi driver task: 3ffc3eb8, prio:23, stack:6656, core=0
I (622) system_api: Base MAC address is not set
I (622) system_api: read default base MAC address from EFUSE
I (632) wifi:wifi firmware version: c7d0450
I (632) wifi:wifi certification version: v7.0
I (632) wifi:config NVS flash: enabled
I (632) wifi:config nano formating: disabled
I (642) wifi:Init data frame dynamic rx buffer num: 32
I (642) wifi:Init management frame dynamic rx buffer num: 32
I (652) wifi:Init management short buffer num: 32
I (652) wifi:Init dynamic tx buffer num: 32
I (662) wifi:Init static rx buffer size: 1600
I (662) wifi:Init static rx buffer num: 10
I (662) wifi:Init dynamic rx buffer num: 32
I (672) wifi_init: rx ba win: 6
I (672) wifi_init: tcpip mbox: 32
I (682) wifi_init: udp mbox: 6
I (682) wifi_init: tcp mbox: 6
I (682) wifi_init: tcp tx win: 5744
I (692) wifi_init: tcp rx win: 5744
I (692) wifi_init: tcp mss: 1440
I (702) wifi_init: WiFi IRAM OP enabled
I (702) wifi_init: WiFi RX IRAM OP enabled
I (2612) ethernet: working in 10Mbps
I (2612) ethernet: working in half duplex
I (2612) ethernet: Ethernet Link Up
I (2612) ethernet: Ethernet HW Addr 02:04:a3:12:34:56
I (2612) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (2742) wifi:mode : softAP (02:04:a3:12:34:56)
I (2742) wifi:Total power save buffer number: 16
I (2742) wifi:Init max length of beacon: 752/752
I (2742) wifi:Init max length of beacon: 752/752
I (3582) esp_netif_handlers: eth ip: 192.168.86.96, mask: 255.255.255.0, gw: 192.168.86.1
I (3582) ethernet: Ethernet Got IP Address
I (3582) ethernet: ~~~~~~~~~~~
I (3582) ethernet: ETHIP:192.168.86.96
I (3592) ethernet: ETHMASK:255.255.255.0
I (3592) ethernet: ETHGW:192.168.86.1
I (3602) ethernet: ~~~~~~~~~~~
I (11402) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (11402) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (11432) ethernet: Wi-Fi AP got a station connected
E (11462) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (11462) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (11462) ethernet: enc28j60_read_packet(279): read memory failed
E (11472) ethernet: emac_enc28j60_receive(725): read packet content failed
E (11482) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (11482) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (11492) ethernet: enc28j60_read_packet(279): read memory failed
E (11502) ethernet: emac_enc28j60_receive(725): read packet content failed
E (11512) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (11512) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (11522) ethernet: enc28j60_read_packet(279): read memory failed
E (11532) ethernet: emac_enc28j60_receive(725): read packet content failed
E (11542) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (11542) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (11552) ethernet: enc28j60_read_packet(279): read memory failed
E (11562) ethernet: emac_enc28j60_receive(725): read packet content failed
E (11752) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (11752) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (11752) ethernet: enc28j60_read_packet(279): read memory failed
E (11762) ethernet: emac_enc28j60_receive(725): read packet content failed
E (12432) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (12432) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (12432) ethernet: enc28j60_read_packet(279): read memory failed
E (12442) ethernet: emac_enc28j60_receive(725): read packet content failed
E (13452) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (13452) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (13452) ethernet: enc28j60_read_packet(279): read memory failed
E (13462) ethernet: emac_enc28j60_receive(725): read packet content failed
E (13472) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (13932) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (13932) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (13932) ethernet: enc28j60_read_packet(279): read memory failed
E (13942) ethernet: emac_enc28j60_receive(725): read packet content failed
E (14422) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (14422) ethernet: Ethernet send packet failed
E (14592) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (14592) ethernet: Ethernet send packet failed
E (14662) ethernet: enc28j60_switch_register_bank(231): clear ECON1[1:0] failed
E (14662) ethernet: enc28j60_register_read(261): switch bank failed
E (14662) ethernet: emac_enc28j60_read_phy_reg(332): read MISTAT failed
E (14672) ethernet: enc28j60_update_link_duplex_speed(865): read PHSTAT2 failed
E (14672) ethernet: enc28j60_get_link(904): update link duplex speed failed
E (15932) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (15932) ethernet: Ethernet send packet failed
E (16662) ethernet: enc28j60_switch_register_bank(231): clear ECON1[1:0] failed
E (16662) ethernet: enc28j60_register_read(261): switch bank failed
E (16662) ethernet: emac_enc28j60_read_phy_reg(332): read MISTAT failed
E (16672) ethernet: enc28j60_update_link_duplex_speed(865): read PHSTAT2 failed
E (16672) ethernet: enc28j60_get_link(904): update link duplex speed failed
E (19272) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (19272) ethernet: Ethernet send packet failed
E (21412) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (21422) ethernet: Ethernet send packet failed
E (26562) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (26562) ethernet: Ethernet send packet failed
E (26612) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
I (26612) ethernet: Ethernet Link Down
I (26612) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffc9544
I (26622) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (26692) wifi:flush txq
I (26692) wifi:stop sw txq
I (26692) wifi:lmac stop hw txq
I (26692) ethernet: Wi-Fi AP got a station disconnected
I (28612) ethernet: working in 10Mbps
I (28612) ethernet: working in half duplex
E (28612) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
I (28612) ethernet: Ethernet Link Up
I (28622) ethernet: Ethernet HW Addr 02:04:a3:12:34:56
I (28622) wifi:mode : softAP (02:04:a3:12:34:56)
I (28632) wifi:Total power save buffer number: 16
E (29082) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (30082) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (32082) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
I (34492) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (34502) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (34512) ethernet: Wi-Fi AP got a station connected
E (34522) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (34522) ethernet: Ethernet send packet failed
E (35512) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (35512) ethernet: Ethernet send packet failed
E (36132) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (38002) ethernet: enc28j60_switch_register_bank(231): clear ECON1[1:0] failed
E (38002) ethernet: enc28j60_register_read(261): switch bank failed
E (38002) ethernet: emac_enc28j60_read_phy_reg(332): read MISTAT failed
E (38012) ethernet: enc28j60_update_link_duplex_speed(865): read PHSTAT2 failed
E (38012) ethernet: enc28j60_get_link(904): update link duplex speed failed
E (42552) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (42562) ethernet: Ethernet send packet failed
E (43842) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (43842) ethernet: Ethernet send packet failed
E (44082) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (56442) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (56442) ethernet: Ethernet send packet failed
I (56452) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffba250
I (56452) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (56462) ethernet: Wi-Fi AP got a station disconnected
E (59082) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
Best regards,
P

UPDATE:
Suddenly this started happening, what could be happening?

Code: Select all


E (3827470) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827480) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827490) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827500) ethernet: enc28j60_read_packet(279): read memory failed
E (3827500) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827510) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827520) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827520) ethernet: enc28j60_read_packet(279): read memory failed
E (3827530) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827540) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827550) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827550) ethernet: enc28j60_read_packet(279): read memory failed
E (3827560) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827570) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (3827570) task_wdt:  - IDLE (CPU 0)
E (3827570) task_wdt: Tasks currently running:
E (3827570) task_wdt: CPU 0: enc28j60_tsk
E (3827570) task_wdt: CPU 1: IDLE
E (3827570) task_wdt: Print CPU 0 (current core) backtrace


Backtrace:0x400FA52B:0x3FFB0810 0x40082AFD:0x3FFB0830 0x400D4702:0x3FFC1350 0x400D53FD:0x3FFC1370 0x400D4301:0x3FFC1390 0x4000BD83:0x3FFC13B0 0x4000117D:0x3FFC13D0 0x400592FE:0x3FFC13F0 0x4005937A:0x3FFC1410 0x40058BBF:0x3FFC1430 0x4013BB23:0x3FFC1460 0x40141107:0x3FFC1490 0x40141289:0x3FFC17A0 0x4014978D:0x3FFC17D0 0x4008F669:0x3FFC1800 0x40084BED:0x3FFC1850 0x400850C8:0x3FFC1880 0x40085218:0x3FFC18B0 0x400D9944:0x3FFC18D0 0x400DA325:0x3FFC1930 0x400DA3AD:0x3FFC1960 0x400D9721:0x3FFC19A0 0x4008CB45:0x3FFC19D0 
0x400fa52b: task_wdt_isr at /home/pablo/esp/esp-idf43/components/esp_common/src/task_wdt.c:189

0x40082afd: _xt_lowint1 at /home/pablo/esp/esp-idf43/components/freertos/port/xtensa/xtensa_vectors.S:1105

0x400d4702: uart_tx_char at /home/pablo/esp/esp-idf43/components/vfs/vfs_uart.c:160 (discriminator 1)

0x400d53fd: uart_write at /home/pablo/esp/esp-idf43/components/vfs/vfs_uart.c:217

0x400d4301: esp_vfs_write at /home/pablo/esp/esp-idf43/components/vfs/vfs.c:423 (discriminator 4)

0x4013bb23: __sprint_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:433
 (inlined by) __sprint_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:403

0x40141107: _vfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:1781 (discriminator 1)

0x40141289: vprintf at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vprintf.c:34 (discriminator 5)

0x4014978d: esp_log_writev at /home/pablo/esp/esp-idf43/components/log/log.c:189

0x4008f669: esp_log_write at /home/pablo/esp/esp-idf43/components/log/log.c:199

0x40084bed: check_trans_valid at /home/pablo/esp/esp-idf43/components/driver/spi_master.c:694 (discriminator 5)

0x400850c8: spi_device_polling_start at /home/pablo/esp/esp-idf43/components/driver/spi_master.c:926 (discriminator 2)

0x40085218: spi_device_polling_transmit at /home/pablo/esp/esp-idf43/components/driver/spi_master.c:984

0x400d9944: enc28j60_do_memory_read at /home/pablo/RTU-X/Software/15_Module_Ethernet/build/../components/src/ethernet.c:186

0x400da325: enc28j60_read_packet at /home/pablo/RTU-X/Software/15_Module_Ethernet/build/../components/src/ethernet.c:278 (discriminator 2)

0x400da3ad: emac_enc28j60_receive at /home/pablo/RTU-X/Software/15_Module_Ethernet/build/../components/src/ethernet.c:724 (discriminator 2)

0x400d9721: emac_enc28j60_task at /home/pablo/RTU-X/Software/15_Module_Ethernet/build/../components/src/ethernet.c:580

0x4008cb45: vPortTaskWrapper at /home/pablo/esp/esp-idf43/components/freertos/port/xtensa/port.c:168


E (3827570) task_wdt: Print CPU 1 backtrace


Backtrace:0x40085731:0x3FFB0E10 0x40082AFD:0x3FFB0E30 0x4000BFED:0x3FFBC220 0x4008CDAE:0x3FFBC230 0x400FA7CF:0x3FFBC250 0x400FA7DB:0x3FFBC280 0x400D8181:0x3FFBC2A0 0x4008AA4D:0x3FFBC2C0 0x4008CB45:0x3FFBC2E0 
0x40085731: esp_crosscore_isr at /home/pablo/esp/esp-idf43/components/esp32/crosscore_int.c:77

0x40082afd: _xt_lowint1 at /home/pablo/esp/esp-idf43/components/freertos/port/xtensa/xtensa_vectors.S:1105

0x4008cdae: vPortExitCritical at /home/pablo/esp/esp-idf43/components/freertos/port/xtensa/port.c:472

0x400fa7cf: esp_task_wdt_reset at /home/pablo/esp/esp-idf43/components/esp_common/src/task_wdt.c:336

0x400fa7db: idle_hook_cb at /home/pablo/esp/esp-idf43/components/esp_common/src/task_wdt.c:88

0x400d8181: esp_vApplicationIdleHook at /home/pablo/esp/esp-idf43/components/esp_common/src/freertos_hooks.c:51 (discriminator 1)

0x4008aa4d: prvIdleTask at /home/pablo/esp/esp-idf43/components/freertos/tasks.c:3839 (discriminator 1)

0x4008cb45: vPortTaskWrapper at /home/pablo/esp/esp-idf43/components/freertos/port/xtensa/port.c:168


;31mE (3827570) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827680) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827690) ethernet: enc28j60_read_packet(279): read memory failed
E (3827700) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827700) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827710) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827720) ethernet: enc28j60_read_packet(279): read memory failed
E (3827730) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827730) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827740) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827750) ethernet: enc28j60_read_packet(279): read memory failed
E (3827760) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827760) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827770) ethernet: enc28j60_do_memory_read(187): spi transmit failed
E (3827780) ethernet: enc28j60_read_packet(279): read memory failed
E (3827780) ethernet: emac_enc28j60_receive(725): read packet content failed
E (3827790) spi_master: check_trans_valid(694): txdata transfer > host maximum
E (3827800) ethernet: enc28j60_do_memory_read(187): spi transmit failed
More UPDATE:

I've got the next log output:

Code: Select all

entry 0x40080678
I (27) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (27) boot: compile time 17:11:12
I (27) boot: chip revision: 3
I (30) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed      : 40MHz
I (42) boot.esp32: SPI Mode       : DIO
I (47) boot.esp32: SPI Flash Size : 16MB
I (51) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (67) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (75) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (82) boot:  2 factory          factory app      00 00 00010000 00100000
I (90) boot: End of partition table
I (94) boot_comm: chip revision: 3, min. application chip revision: 0
I (101) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1b388h (111496) map
I (152) esp_image: segment 1: paddr=0002b3b0 vaddr=3ffb0000 size=04478h ( 17528) load
I (159) esp_image: segment 2: paddr=0002f830 vaddr=40080000 size=007e8h (  2024) load
I (160) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=79788h (497544) map
I (354) esp_image: segment 4: paddr=000a97b0 vaddr=400807e8 size=16798h ( 92056) load
I (393) esp_image: segment 5: paddr=000bff50 vaddr=50000000 size=00010h (    16) load
I (406) boot: Loaded app from partition at offset 0x10000
I (406) boot: Disabling RNG early entropy source...
I (418) cpu_start: Pro cpu up.
I (418) cpu_start: Starting app cpu, entry point is 0x400813f4
0x400813f4: call_start_cpu1 at /home/pablo/esp/esp-idf43/components/esp_system/port/cpu_start.c:141

I (405) cpu_start: App cpu up.
I (432) cpu_start: Pro cpu start user code
I (432) cpu_start: cpu freq: 160000000
I (432) cpu_start: Application information:
I (437) cpu_start: Project name:     ethernet_module
I (442) cpu_start: App version:      v3.2.02-146-gf31edc4-dirty
I (449) cpu_start: Compile time:     Oct 28 2021 17:11:06
I (455) cpu_start: ELF file SHA256:  6e6a2c5837063e3e...
I (461) cpu_start: ESP-IDF:          v4.3-dirty
I (466) heap_init: Initializing. RAM available for dynamic allocation:
I (473) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (480) heap_init: At 3FFB8130 len 00027ED0 (159 KiB): DRAM
I (486) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (492) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (499) heap_init: At 40096F80 len 00009080 (36 KiB): IRAM
I (506) spi_flash: detected chip: generic
I (509) spi_flash: flash io: dio
I (515) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (564) ethernet: revision: 6
I (584) esp_eth.netif.glue: 02:04:a3:12:34:56
I (584) esp_eth.netif.glue: ethernet attached to netif
I (594) ethernet: Ethernet Started
I (604) wifi:wifi driver task: 3ffc3eb8, prio:23, stack:6656, core=0
I (604) system_api: Base MAC address is not set
I (604) system_api: read default base MAC address from EFUSE
I (604) wifi:wifi firmware version: c7d0450
I (614) wifi:wifi certification version: v7.0
I (614) wifi:config NVS flash: enabled
I (614) wifi:config nano formating: disabled
I (624) wifi:Init data frame dynamic rx buffer num: 32
I (624) wifi:Init management frame dynamic rx buffer num: 32
I (634) wifi:Init management short buffer num: 32
I (634) wifi:Init dynamic tx buffer num: 32
I (644) wifi:Init static rx buffer size: 1600
I (644) wifi:Init static rx buffer num: 10
I (644) wifi:Init dynamic rx buffer num: 32
I (654) wifi_init: rx ba win: 6
I (654) wifi_init: tcpip mbox: 32
I (664) wifi_init: udp mbox: 6
I (664) wifi_init: tcp mbox: 6
I (664) wifi_init: tcp tx win: 5744
I (674) wifi_init: tcp rx win: 5744
I (674) wifi_init: tcp mss: 1440
I (684) wifi_init: WiFi IRAM OP enabled
I (684) wifi_init: WiFi RX IRAM OP enabled
I (2594) ethernet: working in 10Mbps
I (2594) ethernet: working in half duplex
I (2594) ethernet: Ethernet Link Up
I (2594) ethernet: Ethernet HW Addr 02:04:a3:12:34:56
I (2594) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
W (2804) phy_init: saving new calibration data because of checksum failure, mode(0)
I (2824) wifi:mode : softAP (02:04:a3:12:34:56)
I (2824) wifi:Total power save buffer number: 16
I (2824) wifi:Init max length of beacon: 752/752
I (2834) wifi:Init max length of beacon: 752/752
I (3564) esp_netif_handlers: eth ip: 192.168.86.96, mask: 255.255.255.0, gw: 192.168.86.1
I (3564) ethernet: Ethernet Got IP Address
I (3564) ethernet: ~~~~~~~~~~~
I (3564) ethernet: ETHIP:192.168.86.96
I (3574) ethernet: ETHMASK:255.255.255.0
I (3574) ethernet: ETHGW:192.168.86.1
I (3584) ethernet: ~~~~~~~~~~~
I (13654) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (13664) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (13674) ethernet: Wi-Fi AP got a station connected
E (13744) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (13744) ethernet: Ethernet send packet failed
E (13934) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (13934) ethernet: Ethernet send packet failed
E (14084) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (14084) ethernet: Ethernet send packet failed
E (14644) ethernet: enc28j60_switch_register_bank(231): clear ECON1[1:0] failed
E (14644) ethernet: enc28j60_register_read(261): switch bank failed
E (14644) ethernet: emac_enc28j60_read_phy_reg(332): read MISTAT failed
E (14654) ethernet: enc28j60_update_link_duplex_speed(865): read PHSTAT2 failed
E (14654) ethernet: enc28j60_get_link(904): update link duplex speed failed
E (14944) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (14944) ethernet: Ethernet send packet failed
E (14994) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (14994) ethernet: Ethernet send packet failed
E (15174) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (15174) ethernet: Ethernet send packet failed
E (15594) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (15594) ethernet: Ethernet send packet failed
E (15644) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (15644) ethernet: Ethernet send packet failed
E (15964) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (15964) ethernet: Ethernet send packet failed
E (16494) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (16494) ethernet: Ethernet send packet failed
E (16834) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (16834) ethernet: Ethernet send packet failed
E (17644) ethernet: emac_enc28j60_transmit(678): read ECON1 failed
E (17644) ethernet: Ethernet send packet failed
I (59174) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffc9720
I (59174) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (59184) ethernet: Wi-Fi AP got a station disconnected
Here it says it can't read the ECON1 register from the ENC28J60, but a small while before the ESP-WROOM was able to get the assigned IP address of the network, which I guess it gets the same ways as it reads the ECON1 register.. so, not sure what could be wrong there. Any idea?

Best regards,
P

NorbertoNorbs
Posts: 2
Joined: Fri Oct 29, 2021 1:28 am

Re: eth2ap not able to connect to internet

Postby NorbertoNorbs » Fri Oct 29, 2021 1:33 am

My guess is that since you're bridging ethernet directly to the AP you can't attach the ESP32 tcp/ip stack, so you will have to remove the netif calls
Eg.: esp_netif_new, esp_netif_attach, esp_eth_start

Also is there a reason why you commented the line .cs_ena_posttrans = enc28j60_cal_spi_cs_hold_time(6)?
I found it very important in my project when working with ENC28J60.

Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

Re: eth2ap not able to connect to internet

Postby Palonso » Tue Nov 16, 2021 2:14 pm

Hi NorbertoNorbs,

It was as you said, I was attaching things to TCP/IP stack but I only wanted MAC layer things done.
Here is the code I ended up with:

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_eth.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "driver/uart.h"

#include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_private/wifi.h"

const char *TAG = "ethernet";

esp_eth_handle_t eth_handle = NULL;
QueueHandle_t flow_control_queue = NULL;
bool s_sta_is_connected = false;
bool s_ethernet_is_connected = false;

// Forward packets from Wi-Fi to Ethernet
esp_err_t pkt_wifi2eth(void *buffer, uint16_t len, void *eb)
{
    if (s_ethernet_is_connected) {
        if (esp_eth_transmit(eth_handle, buffer, len) != ESP_OK) {
            ESP_LOGE(TAG, "Ethernet send packet failed");
        }
    }
    // ESP_LOG_BUFFER_HEX("output", buffer,len);
    esp_wifi_internal_free_rx_buffer(eb);
    return ESP_OK;
}

// Forward packets from Ethernet to Wi-Fi
// Note that, Ethernet works faster than Wi-Fi on ESP32,
// so we need to add an extra queue to balance their speed difference.
esp_err_t pkt_eth2wifi(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t len, void* priv)
{
    esp_err_t ret = ESP_OK;
    flow_control_msg_t msg = {
        .packet = buffer,
        .length = len
    };
    if (xQueueSend(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) != pdTRUE) {
        ESP_LOGE(TAG, "send flow control message failed or timeout");
        free(buffer);
        ret = ESP_FAIL;
    }
    // ESP_LOG_BUFFER_HEX("input", buffer,len);
    return ret;
}

// This task will fetch the packet from the queue, and then send out through Wi-Fi.
// Wi-Fi handles packets slower than Ethernet, we might add some delay between each transmitting.
void eth2wifi_flow_control_task(void *args)
{
    flow_control_msg_t msg;
    int res = 0;
    uint32_t timeout = 0;
    while (1) {
        if (xQueueReceive(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) == pdTRUE) {
            timeout = 0;
            if (s_sta_is_connected && msg.length) {
                do {
                    vTaskDelay(pdMS_TO_TICKS(timeout));
                    timeout += 2;
                    res = esp_wifi_internal_tx(ESP_IF_WIFI_AP, msg.packet, msg.length);
                } while (res && timeout < FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS);
                if (res != ESP_OK) {
                    ESP_LOGE(TAG, "WiFi send packet failed: %d", res);
                }
            }
            free(msg.packet);
        }
    }
    vTaskDelete(NULL);
}


/** Event handler for Ethernet events */
void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    uint8_t mac_addr[6] = {0};
    /* we can get the ethernet driver handle from event data */
    esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;

    switch (event_id) 
    {
        case ETHERNET_EVENT_CONNECTED:
            ESP_LOGI(TAG, "Ethernet Link Up");
            s_ethernet_is_connected = true;
            esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);    //Obtengo direccion MAC
            ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
            esp_wifi_set_mac(WIFI_IF_AP, mac_addr);
            ESP_ERROR_CHECK(esp_wifi_start());
            break;
        case ETHERNET_EVENT_DISCONNECTED:
            ESP_LOGI(TAG, "Ethernet Link Down");
            s_ethernet_is_connected = false;
            ESP_ERROR_CHECK(esp_wifi_stop());
            break;
        case ETHERNET_EVENT_START:
            ESP_LOGI(TAG, "Ethernet Started");
            break;
        case ETHERNET_EVENT_STOP:
            ESP_LOGI(TAG, "Ethernet Stopped");
            break;
        default:
            break;
    }
}

// Event handler for Wi-Fi
void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    uint8_t s_con_cnt = 0;
    switch (event_id) 
    {
        case WIFI_EVENT_AP_STACONNECTED:
            ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
            if (!s_con_cnt)
            {
                s_sta_is_connected = true;
                esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, pkt_wifi2eth);
            }
            s_con_cnt++;
            break;
        case WIFI_EVENT_AP_STADISCONNECTED:
            ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
            s_con_cnt--;
            if (!s_con_cnt)
            {
                s_sta_is_connected = false;
                esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL);
            }
            break;
        default:
            break;
    }
}

void initialize_ethernet(void)
{
    ESP_ERROR_CHECK(gpio_install_isr_service(0));
    ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));

    /* SPI Bus configuration */
    spi_bus_config_t buscfg = {
        .miso_io_num = GPIO_NUM_25,
        .mosi_io_num = GPIO_NUM_23,
        .sclk_io_num = GPIO_NUM_19,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
    };
    ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, 1));

    /* 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 = SPI_CLOCK_6MHZ,
        .spics_io_num = GPIO_NUM_22,
        .queue_size = 20
    };
    spi_device_handle_t spi_handle = NULL;
    ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg, &spi_handle));

    /* enc28j60 ethernet driver is based on spi driver */
    eth_enc28j60_config_t enc28j60_config = ETH_ENC28J60_DEFAULT_CONFIG(spi_handle);
    enc28j60_config.int_gpio_num = GPIO_NUM_4;
    
    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 *eth_mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config);

    eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
    // phy_config.phy_addr = 0;
    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);

    // CONFIG_ETH_USE_SPI_ETHERNET
    esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, phy);
    eth_config.stack_input = pkt_eth2wifi;
    ESP_ERROR_CHECK(esp_eth_driver_install(&eth_config, &eth_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.
     */ 
    eth_mac->set_addr(eth_mac, (uint8_t[]) {0x05, 0x04, 0xA3, 0x12, 0x34, 0x56});

    /* start Ethernet driver state machine */
    esp_eth_ioctl(eth_handle, ETH_CMD_S_PROMISCUOUS, (void *)true);
    esp_eth_start(eth_handle);
}

void initialize_wifi(void)
{
    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL));

	// _wifi_ap = esp_netif_create_default_wifi_ap();

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);
    esp_wifi_set_storage(WIFI_STORAGE_RAM);

    esp_wifi_set_mode(WIFI_MODE_AP);

    wifi_config_t wifi_config = {
        .ap = {
            .ssid = "TEST_SSID",
            .ssid_len = strlen("TEST_SSID"),
            .password = "testtest",
            .max_connection = 5,
            .authmode = WIFI_AUTH_WPA_WPA2_PSK,
            .channel = 1 // default: channel 1
        },
    };
    if (wifi_config.ap.ssid_len == 0) {
        wifi_config.ap.authmode = WIFI_AUTH_OPEN;
    }
    esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config);
}

esp_err_t initialize_flow_control(void)
{
    flow_control_queue = xQueueCreate(FLOW_CONTROL_QUEUE_LENGTH, sizeof(flow_control_msg_t));
    if (!flow_control_queue) {
        ESP_LOGE(TAG, "create flow control queue failed");
        return ESP_FAIL;
    }
    BaseType_t ret = xTaskCreate(eth2wifi_flow_control_task, "flow_ctl", 2048, NULL, (tskIDLE_PRIORITY + 2), NULL);
    if (ret != pdTRUE) {
        ESP_LOGE(TAG, "create flow control task failed");
        return ESP_FAIL;
    }
    return ESP_OK;
}

void app_main(void)
{
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);
    esp_event_loop_create_default();
    initialize_flow_control();

    initialize_ethernet();
    initialize_wifi();
}
My next cuestion is that I'm getting the next message in the console log:

Code: Select all

I (20378) ethernet: Wi-Fi AP got a station connected
W (26888) wifi:<ba-add>idx:4 (ifx:1, d0:37:45:17:0e:2c), tid:0, ssn:19, winSize:64
E (28338) ethernet: WiFi send packet failed: 12309
E (29888) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (29888) ethernet: Ethernet send packet failed
E (30588) ethernet: WiFi send packet failed: 12309
E (32368) ethernet: send flow control message failed or timeout
E (32668) ethernet: send flow control message failed or timeout
E (32838) ethernet: WiFi send packet failed: 12309
E (33988) ethernet: send flow control message failed or timeout
E (34248) ethernet: send flow control message failed or timeout
E (34418) ethernet: send flow control message failed or timeout
E (34518) ethernet: send flow control message failed or timeout
E (34718) ethernet: send flow control message failed or timeout
E (35028) ethernet: send flow control message failed or timeout
E (35088) ethernet: WiFi send packet failed: 12309
E (36458) ethernet: send flow control message failed or timeout
E (36558) ethernet: send flow control message failed or timeout
E (37338) ethernet: WiFi send packet failed: 12309
E (38718) ethernet: send flow control message failed or timeout
Is there any way to fix this? or whats happening?

Best regards,
P

UPDATE:

On the GitHub read-me explained how to "troubleshoot" those messages, yet enlarging FLOW_CONTROL_QUEUE_LENGTH to 255 and FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS to 5000, seems a bit too excessive for this purpose. Also, now I'm having memory issues, probably due to the #defines enlargement (no mem for receive buffer).

Other thing I noticed is that I received an IP from the network I want to connect, but no access to internet. On the output console I managed to print the packets traffic and I get wifi2eth packets and eth2wifi packets going through the ESP.

Any idea of what could be going on?

code used:
main.c
(9.27 KiB) Downloaded 494 times
ethernet.c
(38.94 KiB) Downloaded 430 times
ethernet.h
(17.38 KiB) Downloaded 459 times
Best regards,
P

UPDATE 2:

I found the problem, or at least now it connects to internet, I had the internal EMAC controller available in the sdkconfig file. After uncheck that option it started working.

Still got a lot of:

Code: Select all

E (12300) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (12300) ethernet: Ethernet send packet failed
E (12440) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (12440) ethernet: Ethernet send packet failed
E (12490) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (12490) ethernet: Ethernet send packet failed
E (12610) ethernet: emac_enc28j60_transmit(679): last transmit still in progress
E (12610) ethernet: Ethernet send packet failed
messages, but probably there is some timing thing involved.

UPDATE 3:

Another problem came up, is that the example some days it works and some other don't, here is what happens:

Code: Select all

I (150510) ethernet: working in 10Mbps
I (150510) ethernet: working in half duplex
I (150510) ethernet: Ethernet Link Up
I (150510) ethernet: Ethernet HW Addr 1c:9d:c2:49:be:f7
I (150520) wifi:mode : softAP (1c:9d:c2:49:be:f7)
I (150520) wifi:Total power save buffer number: 16
I (158410) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (158410) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (158450) ethernet: Wi-Fi AP got a station connected
I (158510) ethernet: Ethernet Link Down
I (158510) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffc6e64
I (158510) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (158590) wifi:flush txq
I (158590) wifi:stop sw txq
I (158590) wifi:lmac stop hw txq
I (158590) ethernet: Wi-Fi AP got a station disconnected
I (160510) ethernet: working in 10Mbps
I (160510) ethernet: working in half duplex
I (160510) ethernet: Ethernet Link Up
I (160510) ethernet: Ethernet HW Addr 1c:9d:c2:49:be:f7
I (160520) wifi:mode : softAP (1c:9d:c2:49:be:f7)
I (160520) wifi:Total power save buffer number: 16
I (166440) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (166440) wifi:station: d0:37:45:17:0e:2c join, AID=1, bgn, 40U
I (166460) ethernet: Wi-Fi AP got a station connected
I (166510) ethernet: Ethernet Link Down
I (166510) wifi:station: d0:37:45:17:0e:2c leave, AID = 1, bss_flags is 658531, bss:0x3ffc6e64
I (166510) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (166600) wifi:flush txq
I (166600) wifi:stop sw txq
I (166600) wifi:lmac stop hw txq
I (166600) ethernet: Wi-Fi AP got a station disconnected
And it does this over and over. Any idea of what could be happening?

Regards,
P


Last bumped by Palonso on Tue Nov 16, 2021 2:14 pm.

Who is online

Users browsing this forum: robizzar72 and 55 guests