A stack overflow in task w5500_tsk has been detected

chikichaka
Posts: 14
Joined: Tue Aug 09, 2022 7:53 am

A stack overflow in task w5500_tsk has been detected

Postby chikichaka » Mon Apr 24, 2023 3:37 am

I use ethernet by using W5500 and ESP-IDF driver and implement MODBUS TCP communication.
After 30~40min, I could see this stack overflow error.
Also I use display illi9341 and DAC to same SPI bus.
How can I solve this problem?
Some people say that malfunction of W5500. However I don not know exactly reason for this.

I used code from ESP-IDF 5.0.1 Example code.

https://github.com/espressif/esp-idf/bl ... ple_main.c
https://github.com/espressif/esp-idf/tr ... tcp_master



E (1796070) w5500.mac: w5500_read(98): spi transmit failed
E (1796070) w5500.mac: w5500_read_buffer(193): read RX buffer failed
E (1796080
***ERROR*** A stack overflow in task w5500_tsk has been detected.

ESP_ondrej
Posts: 166
Joined: Fri May 07, 2021 10:35 am

Re: A stack overflow in task w5500_tsk has been detected

Postby ESP_ondrej » Mon Apr 24, 2023 10:15 am

Stack overflow is probably caused by error printing. You can try to increase `rx_task_stack_size` of `eth_mac_config_t`config structure. However, it would worth investigating why you got `spi transmit failed` error.

chikichaka
Posts: 14
Joined: Tue Aug 09, 2022 7:53 am

Re: A stack overflow in task w5500_tsk has been detected

Postby chikichaka » Wed Apr 26, 2023 8:04 am

ESP_ondrej wrote:
Mon Apr 24, 2023 10:15 am
Stack overflow is probably caused by error printing. You can try to increase `rx_task_stack_size` of `eth_mac_config_t`config structure. However, it would worth investigating why you got `spi transmit failed` error.
Thanks for your reply.

I changed rx_task_stack_size and I could not see stack overflow error.
However, I could see this error after 2hour ~3hour MODBUS TCP Communication.
It could be hardware problem??
MB_TCP_SLAVE_PORT: Receive failed: length=-1, errno=113
MB_TCP_SLAVE_PORT: Socket (#59)(192.168.9.198), read data error:-1
MB_TCP_SLAVE_PORT: Socket (#59), shutdown failed: errno 128

monyster
Posts: 4
Joined: Wed May 31, 2023 6:53 am

Re: A stack overflow in task w5500_tsk has been detected

Postby monyster » Wed May 31, 2023 7:37 am

Hi! Did you solve this problem because I have the same one?
Using:
- ESP-IDF 5.
- ESP32-S3.

E (1479766) w5500.mac: w5500_read(98): spi transmit failed
E (1479766) w5500.mac: w5500_read_buffer(193): read RX buffer failed
E (1479766) w5500.mac: emac_w5500_receive(576): read payload failed, len=316, offset=49071
E (1479776) w5500.mac: frame read from module failed

***ERROR*** A stack overflow in task w5500_tsk has been detected.


Backtrace: 0x4037627a:0x3fca28f0 0x4037d315:0x3fca2910 0x4038048e:0x3fca2930 0x4037f1ef:0x3fca29b0 0x4037d3cc:0x3fca29d0 0x4037d3c2:0x00000000 |<-CORRUPTED
0x4037627a: panic_abort at C:/Users/user/esp/esp-idf/components/esp_system/panic.c:423

0x4037d315: esp_system_abort at C:/Users/user/esp/esp-idf/components/esp_system/esp_system.c:153

0x4038048e: vApplicationStackOverflowHook at C:/Users/user/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:391

0x4037f1ef: vTaskSwitchContext at C:/Users/user/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:3648

0x4037d3cc: _frxt_dispatch at C:/Users/user/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/portasm.S:418

0x4037d3c2: _frxt_int_exit at C:/Users/user/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/portasm.S:213

ESP_ondrej
Posts: 166
Joined: Fri May 07, 2021 10:35 am

Re: A stack overflow in task w5500_tsk has been detected

Postby ESP_ondrej » Wed May 31, 2023 1:52 pm

Do you have other devices connected to the same SPI bus as the W5500 is connected to?

monyster
Posts: 4
Joined: Wed May 31, 2023 6:53 am

Re: A stack overflow in task w5500_tsk has been detected

Postby monyster » Thu Jun 01, 2023 11:49 am

Features:
- 16 MB internal flash memory and 8 MB PSRAM (80 MHz)
- SPI W5500 (5MHZ)
- SD CARD (10MHZ)

SPIFFS for html, js, css, webp and user database.
W5500 for http server.
SD-CARD for sqlite3 log database.

Code: Select all

esp_err_t spiffs_mount(void)
{
    esp_vfs_spiffs_conf_t conf = {
        .base_path = SPIFFS_MOUNT_POINT,
        .partition_label = NULL,
        .max_files = 20,
        .format_if_mount_failed = false};

    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK)
    {
        if (ret == ESP_FAIL)
        {
            ESP_LOGE(TAG, "Failed to mount or format filesystem");
        }
        else if (ret == ESP_ERR_NOT_FOUND)
        {
            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
        }
        else
        {
            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)",
                     esp_err_to_name(ret));
        }
        return ESP_FAIL;
    }

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(NULL, &total, &used);
    if (ret != ESP_OK)
    {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)",
                 esp_err_to_name(ret));
    }
    else
    {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }
    return ESP_OK;
}

Code: Select all

esp_netif_t *eth_netif_spi = NULL;

/** Event handler for Ethernet events */
static 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);
        ESP_LOGI(TAG, "Ethernet Link Up");
        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]);
        break;
    case ETHERNET_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "Ethernet Link Down");
        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 IP_EVENT_ETH_GOT_IP */
static 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 myW5500_connect()
{
    /* ============================================================ */
    // Create instance(s) of esp-netif for SPI Ethernet(s)
    esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
    esp_netif_config.if_key = "[ETH_SPI_W5500]";
    esp_netif_config.if_desc = "[eth]";
    esp_netif_config.route_prio = 30;

    esp_netif_config_t cfg_spi = {
        .base = &esp_netif_config,
        .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH};

    /* ============================================================ */
    eth_netif_spi = esp_netif_new(&cfg_spi);

    /* ============================================================ */
    // Init MAC and PHY configs to default
    eth_mac_config_t mac_config_spi = ETH_MAC_DEFAULT_CONFIG();
    eth_phy_config_t phy_config_spi = ETH_PHY_DEFAULT_CONFIG();

    /* ============================================================ */
    // Install GPIO ISR handler to be able to service SPI Eth modlues interrupts
    gpio_install_isr_service(0);

    /* ============================================================ */
    // Init SPI bus
    spi_bus_config_t buscfg = {
        .miso_io_num = CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
        .mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
        .sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
    };
    ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO));

    /* ============================================================ */
    // Init specific SPI Ethernet module configuration from Kconfig (CS GPIO, Interrupt GPIO, etc.)
    spi_eth_module_config_t spi_eth_module_config;
    spi_eth_module_config.spi_cs_gpio = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO;
    spi_eth_module_config.int_gpio = CONFIG_EXAMPLE_ETH_SPI_INTn_GPIO;
    spi_eth_module_config.phy_reset_gpio = CONFIG_EXAMPLE_ETH_SPI_PHY_RST_GPIO;
    spi_eth_module_config.phy_addr = CONFIG_EXAMPLE_ETH_SPI_PHY_ADDR;

    // Configure SPI interface and Ethernet driver for specific SPI module
    esp_eth_mac_t *mac_spi;
    esp_eth_phy_t *phy_spi;
    esp_eth_handle_t eth_handle_spi = NULL;
    spi_device_interface_config_t spi_devcfg = {
        .mode = 0,
        .clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
        .queue_size = 20};

    // Set SPI module Chip Select GPIO
    spi_devcfg.spics_io_num = spi_eth_module_config.spi_cs_gpio;
    // Set remaining GPIO numbers and configuration used by the SPI module
    phy_config_spi.phy_addr = spi_eth_module_config.phy_addr;
    phy_config_spi.reset_gpio_num = spi_eth_module_config.phy_reset_gpio;

    /* ============================================================ */
    eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
    w5500_config.int_gpio_num = spi_eth_module_config.int_gpio;
    mac_spi = esp_eth_mac_new_w5500(&w5500_config, &mac_config_spi);
    phy_spi = esp_eth_phy_new_w5500(&phy_config_spi);

    /* ============================================================ */
    esp_eth_config_t eth_config_spi = ETH_DEFAULT_CONFIG(mac_spi, phy_spi);
    ESP_ERROR_CHECK(esp_eth_driver_install(&eth_config_spi, &eth_handle_spi));

    /* The SPI Ethernet MAC address */
    ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle_spi,
                                  ETH_CMD_S_MAC_ADDR,
                                  (uint8_t[]){0xAA, 0x77, 0x12, 0x33, 0x44, 0x56}));

    // attach Ethernet driver to TCP/IP stack
    ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi, esp_eth_new_netif_glue(eth_handle_spi)));

    // 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));

    /* start Ethernet driver state machine */
    ESP_ERROR_CHECK(esp_eth_start(eth_handle_spi));
}

Code: Select all

esp_err_t sd_card_mount(void)
{
    sd_card_obj.isMounted = 0;

    esp_err_t ret;

    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = true,
        .max_files = 5,
        .allocation_unit_size = 16 * 1024,
        .disk_status_check_enable = false};

    sdmmc_card_t *card;

    ESP_LOGI(TAG, "Initializing SD card");
    ESP_LOGI(TAG, "Using SPI peripheral");

    sdmmc_host_t host = SDSPI_HOST_DEFAULT();
    host.max_freq_khz = 10000;
    host.slot = SPI3_HOST;


    spi_bus_config_t bus_cfg = {
        .mosi_io_num = PIN_NUM_MOSI,
        .miso_io_num = PIN_NUM_MISO,
        .sclk_io_num = PIN_NUM_CLK,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
        .max_transfer_sz = 4000,
    };

    ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH_AUTO);
    if (ret != ESP_OK)
    {
        ESP_LOGE(TAG, "Failed to initialize bus.");
        sd_card_obj.isMounted = 0;
        return ESP_FAIL;
    }

    // This initializes the slot without card detect (CD) and write protect (WP) signals.
    // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
    slot_config.gpio_cs = PIN_NUM_CS;
    slot_config.host_id = host.slot;

    ret = esp_vfs_fat_sdspi_mount(SDCARD_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
    if (ret != ESP_OK)
    {
        sd_card_obj.isMounted = 0;
        return ESP_FAIL;
    }

    ESP_LOGI(TAG, "SD-Card Successfully installed!");
    sdmmc_card_print_info(stdout, card);

    sd_card_obj.isMounted = 1;
    return ESP_OK;
}

ESP_ondrej
Posts: 166
Joined: Fri May 07, 2021 10:35 am

Re: A stack overflow in task w5500_tsk has been detected

Postby ESP_ondrej » Thu Jun 01, 2023 2:32 pm

Is W5500 connected to the same SPI host as the SD card? It's not clear from shared code.

BTW: https://github.com/espressif/esp-idf/is ... 1571654043

monyster
Posts: 4
Joined: Wed May 31, 2023 6:53 am

Re: A stack overflow in task w5500_tsk has been detected

Postby monyster » Fri Jun 02, 2023 2:19 pm

I didn`t find where to use this function in my code (spi_device_polling_transmit).

I fixed the stack overflow by setting the stack size to LWIP -> tcp/ip -> 8190.

But still new problem:

Code: Select all

E (1266562) w5500.mac: w5500_write(75): spi transmit failed
E (1266562) w5500.mac: w5500_write_buffer(174): write TX buffer failed
E (1266562) w5500.mac: emac_w5500_transmit(478): write frame failed
E (1266722) w5500.mac: emac_w5500_read_phy_reg(335): read PHY register failed
E (1266722) w5500.phy: w5500_update_link_duplex_speed(69): read PHYCFG failed
E (1266722) w5500.phy: w5500_get_link(112): update link duplex speed failed
and

Code: Select all

E (1410042) w5500.mac: w5500_write(75): spi transmit failed
E (1410042) w5500.mac: w5500_write_buffer(174): write TX buffer failed
E (1410042) w5500.mac: emac_w5500_transmit(478): write frame failed
E (1410182) w5500.mac: w5500_get_tx_free_size(137): read TX FSR failed
E (1410182) w5500.mac: emac_w5500_transmit(472): get free size failed
E (1410232) w5500.mac: w5500_get_tx_free_size(137): read TX FSR failed
E (1410232) w5500.mac: emac_w5500_transmit(472): get free size failed
I found out what the problem was. It was the sd-card spi.
If I comment out the sd_card_mount() function, the problem disappears.

Why did the "spi transmit failed"?
I did not use the spi functions directly. I create a pointer to the spi bus and then pass it to the following components (w5500, sd card file system)
Is it possible that I have the spi peripheral configured incorrectly?

Or maybe I forgot to execute free (any malloc) on the http server somewhere?

- W5500 - SPI2_HOST and SPI_DMA_CH_AUTO
- SD-CARD - SPI3_HOST and SPI_DMA_CH_AUTO

Next, I try to make the functions clear:

Code snippet of main.c

Code: Select all

void app_main(void)
{
	ESP_ERROR_CHECK(esp_event_loop_create_default());

	ESP_ERROR_CHECK(nvs_flash_init());
	ESP_ERROR_CHECK(esp_netif_init());

	if (spiffs_mount() != ESP_OK)
	{
		ESP_LOGE(TAG, "spiffs_mount() error!!!");
		return;
	}

	// Initialize sqlite
	sqlite3_initialize();

	sd_card_mount();
	vTaskDelay(pdMS_TO_TICKS(200));
	
	ESP_ERROR_CHECK(start_rest_server(WEB_PATH));
	
	myW5500_connect();
}
Code snippet of w5500 mount

Code: Select all

#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "esp_netif.h"
#include "lwip/ip_addr.h"
#include "esp_eth.h"

#include "esp_event.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

#include "driver/spi_master.h"

#include "myW5500.h"

#define ETH_SPI_MISO_GPIO 40
#define ETH_SPI_MOSI_GPIO 1
#define ETH_SPI_SCLK_GPIO 39

#define ETH_SPI_CS_GPIO 38
#define ETH_SPI_INTn_GPIO 2
#define ETH_SPI_PHY_RST_GPIO 42

#define ETH_SPI_PHY_ADDR 1

#define ETH_SPI_HOST SPI2_HOST

#define ETH_SPI_CLOCK_MHZ 35

static const char *TAG = "W5500_LOG --- ";

esp_netif_t *eth_netif_spi = NULL;

/** Event handler for Ethernet events */
static 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);
        ESP_LOGI(TAG, "Ethernet Link Up");
        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]);
        break;
    case ETHERNET_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "Ethernet Link Down");
        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 IP_EVENT_ETH_GOT_IP */
static 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 myW5500_connect()
{
    /* ============================================================ */
    // Create instance(s) of esp-netif for SPI Ethernet(s)
    esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
    esp_netif_config.if_key = "[ETH_SPI_W5500]";
    esp_netif_config.if_desc = "[eth]";
    esp_netif_config.route_prio = 30;

    esp_netif_config_t cfg_spi = {
        .base = &esp_netif_config,
        .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH};

    /* ============================================================ */
    eth_netif_spi = esp_netif_new(&cfg_spi);

    /* ============================================================ */
    // Init MAC and PHY configs to default
    eth_mac_config_t mac_config_spi = ETH_MAC_DEFAULT_CONFIG();
    eth_phy_config_t phy_config_spi = ETH_PHY_DEFAULT_CONFIG();

    /* ============================================================ */
    // Install GPIO ISR handler to be able to service SPI Eth modlues interrupts
    gpio_install_isr_service(0);

    /* ============================================================ */
    // Init SPI bus
    spi_bus_config_t buscfg = {
        .miso_io_num = ETH_SPI_MISO_GPIO,
        .mosi_io_num = ETH_SPI_MOSI_GPIO,
        .sclk_io_num = ETH_SPI_SCLK_GPIO,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
    };
    ESP_ERROR_CHECK(spi_bus_initialize(ETH_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO));

    /* ============================================================ */
    // Init specific SPI Ethernet module configuration from Kconfig (CS GPIO, Interrupt GPIO, etc.)
    spi_eth_module_config_t spi_eth_module_config;
    spi_eth_module_config.spi_cs_gpio = ETH_SPI_CS_GPIO;
    spi_eth_module_config.int_gpio = ETH_SPI_INTn_GPIO;
    spi_eth_module_config.phy_reset_gpio = ETH_SPI_PHY_RST_GPIO;
    spi_eth_module_config.phy_addr = ETH_SPI_PHY_ADDR;

    // Configure SPI interface and Ethernet driver for specific SPI module
    esp_eth_mac_t *mac_spi;
    esp_eth_phy_t *phy_spi;
    esp_eth_handle_t eth_handle_spi = NULL;
    spi_device_interface_config_t spi_devcfg = {
        .mode = 0,
        .clock_speed_hz = ETH_SPI_CLOCK_MHZ * 1000 * 1000,
        .queue_size = 20};

    // Set SPI module Chip Select GPIO
    spi_devcfg.spics_io_num = spi_eth_module_config.spi_cs_gpio;
    // Set remaining GPIO numbers and configuration used by the SPI module
    phy_config_spi.phy_addr = spi_eth_module_config.phy_addr;
    phy_config_spi.reset_gpio_num = spi_eth_module_config.phy_reset_gpio;

    /* ============================================================ */
    eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(SPI2_HOST, &spi_devcfg);
    w5500_config.int_gpio_num = spi_eth_module_config.int_gpio;
    mac_spi = esp_eth_mac_new_w5500(&w5500_config, &mac_config_spi);
    phy_spi = esp_eth_phy_new_w5500(&phy_config_spi);

    /* ============================================================ */
    esp_eth_config_t eth_config_spi = ETH_DEFAULT_CONFIG(mac_spi, phy_spi);
    ESP_ERROR_CHECK(esp_eth_driver_install(&eth_config_spi, &eth_handle_spi));

    /* The SPI Ethernet MAC address */
    ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle_spi,
                                  ETH_CMD_S_MAC_ADDR,
                                  (uint8_t[]){0xAA, 0x77, 0x12, 0x33, 0x44, 0x56}));

    // attach Ethernet driver to TCP/IP stack
    ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi, esp_eth_new_netif_glue(eth_handle_spi)));

    // 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));

    /* start Ethernet driver state machine */
    ESP_ERROR_CHECK(esp_eth_start(eth_handle_spi));
}
Code snippet of sd-card mount

Code: Select all

#include <stdio.h>

#include "sdmmc_cmd.h"
#include "esp_vfs_fat.h"

#include "sd_card_module.h"

static const char *TAG = "SD_CARD_MODULE >>> ";

sd_card_obj_t sd_card_obj;

esp_err_t sd_card_mount(void)
{
    sd_card_obj.isMounted = 0;
    esp_err_t ret;

    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = true,
        .max_files = 1,
        .allocation_unit_size = 16 * 1024,
        .disk_status_check_enable = false};

    sdmmc_card_t *card;

    ESP_LOGI(TAG, "Initializing SD card");
    ESP_LOGI(TAG, "Using SPI peripheral");

    sdmmc_host_t host = SDSPI_HOST_DEFAULT();
    host.max_freq_khz = 5000;
    host.slot = SPI3_HOST;

    spi_bus_config_t bus_cfg = {
        .mosi_io_num = PIN_NUM_MOSI,
        .miso_io_num = PIN_NUM_MISO,
        .sclk_io_num = PIN_NUM_CLK,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
    };

    ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH_AUTO);
    if (ret != ESP_OK)
    {
        ESP_LOGE(TAG, "Failed to initialize bus.");
        sd_card_obj.isMounted = 0;
        return ESP_FAIL;
    }

    // This initializes the slot without card detect (CD) and write protect (WP) signals.
    // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
    slot_config.gpio_cs = PIN_NUM_CS;
    slot_config.host_id = host.slot;


    ret = esp_vfs_fat_sdspi_mount(SDCARD_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
    if (ret != ESP_OK)
    {
        sd_card_obj.isMounted = 0;
        return ESP_FAIL;
    }

    ESP_LOGI(TAG, "\n\n --- SD-Card Successfully installed!\n\n");
    sdmmc_card_print_info(stdout, card);

    sd_card_obj.isMounted = 1;
    return ESP_OK;
}

monyster
Posts: 4
Joined: Wed May 31, 2023 6:53 am

Re: A stack overflow in task w5500_tsk has been detected

Postby monyster » Wed Jun 07, 2023 6:57 am

-- MY PROBLEM SOLVED --
Thank you for your help.
I solved the problem by changing the initialization order.

Updated main function:

Code: Select all

void app_main(void)
{
	ESP_ERROR_CHECK(esp_event_loop_create_default());

	ESP_ERROR_CHECK(nvs_flash_init());
	ESP_ERROR_CHECK(esp_netif_init());
	vTaskDelay(pdMS_TO_TICKS(200));

	myW5500_connect();
	vTaskDelay(pdMS_TO_TICKS(200));

	if (spiffs_mount() != ESP_OK)
	{
		ESP_LOGE(TAG, "spiffs_mount() error!!!");
		return;
	}
	vTaskDelay(pdMS_TO_TICKS(200));

	if (init_users_db(USERS_DATABASE_PATH) != ESP_OK)
	{
		ESP_LOGE(TAG, "init_users_db() error!!!");
		return;
	}
	vTaskDelay(pdMS_TO_TICKS(200));

	// Initialize sqlite
	sqlite3_initialize();
	vTaskDelay(pdMS_TO_TICKS(200));

	if (sd_card_mount() == ESP_OK)
	{
		sqlite_driver_init(DATABASE_PATH);
		start_sqlite_logger();
	}
	else
	{
		ESP_LOGE(TAG, "sd_card_mount() error!!!");
	}
	vTaskDelay(pdMS_TO_TICKS(200));

	ESP_ERROR_CHECK(start_rest_server(WEB_PATH));
	vTaskDelay(pdMS_TO_TICKS(200));
}

Who is online

Users browsing this forum: Google [Bot] and 126 guests