Error when add new simple task to simple ota project

minhbka
Posts: 8
Joined: Mon Dec 18, 2023 3:15 am

Error when add new simple task to simple ota project

Postby minhbka » Sat Jan 06, 2024 3:36 am

Hi everyone,
I am testing ota update using simple_ota_example project.
The code is working properly when it has ota task only on main function.
When I add new simple task that does the blinking led to main function.
The code of blink_led task is below:

Code: Select all

void blink_task(void *pvParameter)
{

    ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    while (1)
    {

        gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(LED_DELAY_TIME / portTICK_PERIOD_MS);
        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(LED_DELAY_TIME / portTICK_PERIOD_MS);
    }
}
And the code in main function is:

Code: Select all

void app_main(void)
{
ESP_LOGI(TAG, "OTA example app_main start");
    // Initialize NVS.
    esp_err_t err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        // 1.OTA app partition table has a smaller NVS partition size than the non-OTA
        // partition table. This size mismatch may cause NVS initialization to fail.
        // 2.NVS partition contains data in new format and cannot be recognized by this version of code.
        // If this happens, we erase NVS partition and initialize NVS again.
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK(err);

    get_sha256_of_partitions();

    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
     * Read "Establishing Wi-Fi or Ethernet Connection" section in
     * examples/protocols/README.md for more information about this function.
     */
    ESP_ERROR_CHECK(example_connect());

#if CONFIG_EXAMPLE_CONNECT_WIFI
    /* Ensure to disable any WiFi power save mode, this allows best throughput
     * and hence timings for overall OTA operation.
     */
    esp_wifi_set_ps(WIFI_PS_NONE);
#endif // CONFIG_EXAMPLE_CONNECT_WIFI

    xTaskCreate(&simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);
    xTaskCreate(&blink_task, "blink_task", 1024, NULL, 5, NULL);
    }
The output result shows error that in the blink_task a stack overflow is detected

Code: Select all

I (0) cpu_start: App cpu up.
I (517) cpu_start: Pro cpu start user code
I (517) cpu_start: cpu freq: 160000000 Hz
I (518) cpu_start: Application information:
I (522) cpu_start: Project name:     simple_ota
I (527) cpu_start: App version:      1
I (532) cpu_start: Compile time:     Jan  6 2024 00:28:07
I (538) cpu_start: ELF file SHA256:  9247c3bad2202d0b...
I (544) cpu_start: ESP-IDF:          v5.1.2-dirty
I (549) cpu_start: Min chip rev:     v0.0
I (554) cpu_start: Max chip rev:     v3.99 
I (559) cpu_start: Chip rev:         v1.0
I (564) heap_init: Initializing. RAM available for dynamic allocation:
I (571) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (577) heap_init: At 3FFB8380 len 00027C80 (159 KiB): DRAM
I (583) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (589) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (596) heap_init: At 40095C3C len 0000A3C4 (40 KiB): IRAM
I (604) spi_flash: detected chip: generic
I (607) spi_flash: flash io: dio
I (611) app_start: Starting scheduler on CPU0
I (616) app_start: Starting scheduler on CPU1
I (616) main_task: Started on CPU0
I (626) main_task: Calling app_main()
I (626) simple_ota_example: OTA example app_main start
I (676) simple_ota_example: SHA-256 for bootloader:  c75e2652da235b7a8ede83b310e6988bf3e6f8cc78edc83d9a8ad94e4258ef6b
I (906) simple_ota_example: SHA-256 for current firmware:  72b4aa0c5a38182e0327998ae2a1363a246ee3623ceb25e85c24e3779789c2ab
I (906) example_connect: Start example_connect.
I (926) wifi:wifi driver task: 3ffc0060, prio:23, stack:6656, core=0
I (936) wifi:wifi firmware version: 91b9630
I (936) wifi:wifi certification version: v7.0
I (936) wifi:config NVS flash: enabled
I (936) wifi:config nano formating: disabled
I (946) wifi:Init data frame dynamic rx buffer num: 32
I (946) wifi:Init static rx mgmt buffer num: 5
I (946) wifi:Init management short buffer num: 32
I (956) wifi:Init dynamic tx buffer num: 32
I (956) wifi:Init static rx buffer size: 1600
I (966) wifi:Init static rx buffer num: 10
I (966) wifi:Init dynamic rx buffer num: 32
I (976) wifi_init: rx ba win: 6
I (976) wifi_init: tcpip mbox: 32
I (976) wifi_init: udp mbox: 6
I (986) wifi_init: tcp mbox: 6
I (986) wifi_init: tcp tx win: 5744
I (986) wifi_init: tcp rx win: 5744
I (996) wifi_init: tcp mss: 1440
I (996) wifi_init: WiFi IRAM OP enabled
I (1006) wifi_init: WiFi RX IRAM OP enabled
I (1006) phy_init: phy_version 4780,16b31a7,Sep 22 2023,20:42:16
I (1096) wifi:mode : sta (ac:67:b2:3c:6c:00)
I (1096) wifi:enable tsf
I (1096) example_connect: Connecting to U+Net4303...
I (1106) example_connect: Waiting for IP(s)
I (3506) wifi:new:<8,0>, old:<1,0>, ap:<255,255>, sta:<8,0>, prof:1
I (3756) wifi:state: init -> auth (b0)
I (3756) wifi:state: auth -> assoc (0)
I (3766) wifi:state: assoc -> run (10)
I (3776) wifi:<ba-add>idx:0 (ifx:0, 00:08:52:8b:43:01), tid:0, ssn:0, winSize:64
I (3786) wifi:connected with U+Net4303, aid = 7, channel 8, BW20, bssid = 00:08:52:8b:43:01
I (3786) wifi:security: WPA2-PSK, phy: bgn, rssi: -67
I (3796) wifi:pm start, type: 1

I (3836) wifi:AP's beacon interval = 102400 us, DTIM period = 5
I (4906) example_connect: Got IPv6 event: Interface "example_netif_sta" address: fe80:0000:0000:0000:ae67:b2ff:fe3c:6c00, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (5796) esp_netif_handlers: example_netif_sta ip: 192.168.219.115, mask: 255.255.255.0, gw: 192.168.219.1
I (5796) example_connect: Got IPv4 event: Interface "example_netif_sta" address: 192.168.219.115
I (5806) example_common: Connected to example_netif_sta
I (5806) example_common: - IPv4 address: 192.168.219.115,
I (5816) example_common: - IPv6 address: fe80:0000:0000:0000:ae67:b2ff:fe3c:6c00, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (5826) wifi:Set ps type: 0, coexist: 0

I (5826) simple_ota_example: Starting OTA example task
I (5836) simple_ota_example: Attempting to download update from https://raw.githubusercontent.com/minhbka/testUpdateUrl/main/simple_ota.bin

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


Backtrace: 0x400819f6:0x3ffca3c0 0x400890bd:0x3ffca3e0 0x4008be06:0x3ffca400 0x4008a77b:0x3ffca480 0x4008bf54:0x3ffca4a0 0x4008bf06:0x00003009 |<-CORRUPTED
0x400819f6: panic_abort at C:/Users/plati/esp/esp-idf/components/esp_system/panic.c:452

0x400890bd: esp_system_abort at C:/Users/plati/esp/esp-idf/components/esp_system/port/esp_system_chip.c:84

0x4008be06: vApplicationStackOverflowHook at C:/Users/plati/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:581

0x4008a77b: vTaskSwitchContext at C:/Users/plati/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:3728

0x4008bf54: _frxt_dispatch at C:/Users/plati/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/portasm.S:450

0x4008bf06: _frxt_int_exit at C:/Users/plati/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/portasm.S:245
When I put blink_task on top of main function, the output result window keep showing wdt reset.

Code: Select all

void app_main(void)
{
    xTaskCreate(&blink_task, "blink_task", 1024, NULL, 5, NULL);

    ESP_LOGI(TAG, "OTA example app_main start");
    // Initialize NVS.
    esp_err_t err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        // 1.OTA app partition table has a smaller NVS partition size than the non-OTA
        // partition table. This size mismatch may cause NVS initialization to fail.
        // 2.NVS partition contains data in new format and cannot be recognized by this version of code.
        // If this happens, we erase NVS partition and initialize NVS again.
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK(err);

    get_sha256_of_partitions();

    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
     * Read "Establishing Wi-Fi or Ethernet Connection" section in
     * examples/protocols/README.md for more information about this function.
     */
    ESP_ERROR_CHECK(example_connect());

#if CONFIG_EXAMPLE_CONNECT_WIFI
    /* Ensure to disable any WiFi power save mode, this allows best throughput
     * and hence timings for overall OTA operation.
     */
    esp_wifi_set_ps(WIFI_PS_NONE);
#endif // CONFIG_EXAMPLE_CONNECT_WIFI

    xTaskCreate(&simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);
}

Code: Select all

I (0) cpu_start: App cpu up.
I (567) cpu_start: Pro cpu start user code
I (567) cpu_start: cpu freq: 160000000 Hz
I (567) cpu_start: Application information:
I (572) cpu_start: Project name:     simple_ota
I (577) cpu_start: App version:      1
I (581) cpu_start: Compile time:     Jan  6 2024 00:28:07
I (587) cpu_start: ELF file SHA256:  6e8b4f9c211710a5...
I (593) cpu_start: ESP-IDF:          v5.1.2-dirty
I (599) cpu_start: Min chip rev:     v0.0
I (603) cpu_start: Max chip rev:     v3.99 
I (608) cpu_start: Chip rev:         v1.0
I (613) heap_init: Initializing. RAM available for dynamic allocation:
I (620) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (626) heap_init: At 3FFB8380 len 00027C80 (159 KiB): DRAM
I (632) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (639) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (645) heap_init: At 40095C3C len 0000A3C4 (40 KiB): IRAM
I (653) spi_flash: detected chip: generic
I (656) spi_flash: flash io: dio
I (661) app_start: Starting scheduler on CPU0
I (665) app_start: Starting scheduler on CPU1
I (665) main_task: Started on CPU0
I (675) main_task: Calling app_main()
I (675) simple_ota_example: Example configured to blink GPIO LED!
I (685) simple_ota_example: OTA example app_main start
ets Jun  8 2016 00:22:57

rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (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:7084
ho 0 tail 12 room 4
load:0x40078000,len:15584
load:0x40080400,len:4
0x40080400: _init at ??:?

load:0x40080404,len:3876
entry 0x4008064c
I (61) boot: ESP-IDF v5.1.2-dirty 2nd stage bootloader
I (61) boot: compile time Jan  6 2024 00:28:13
I (62) boot: Multicore bootloader
I (67) boot: chip revision: v1.0
I (71) boot.esp32: SPI Speed      : 40MHz
I (75) boot.esp32: SPI Mode       : DIO
I (80) boot.esp32: SPI Flash Size : 4MB
W (84) boot.esp32: PRO CPU has been reset by WDT.
W (90) boot.esp32: WDT reset info: PRO CPU PC=0x400d2a52
0x400d2a52: panic_handler at C:/Users/plati/esp/esp-idf/components/esp_system/port/panic_handler.c:139 (discriminator 2)

W (96) boot.esp32: WDT reset info: APP CPU PC=0x4008c0fc
0x4008c0fc: _xt_context_save at C:/Users/plati/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_context.S:113

Could you please help me to solve the problem?
Thank you.

ESP_Sprite
Posts: 9715
Joined: Thu Nov 26, 2015 4:08 am

Re: Error when add new simple task to simple ota project

Postby ESP_Sprite » Sat Jan 06, 2024 11:50 am

You already found the error: the stack of the blink task overflowed because it has too little stack memory. In the xTaskCreate(&blink_task, "blink_task", 1024, NULL, 5, NULL); line, increase the 1024 to something higher, e.g. 8192.

minhbka
Posts: 8
Joined: Mon Dec 18, 2023 3:15 am

Re: Error when add new simple task to simple ota project

Postby minhbka » Sat Jan 06, 2024 11:56 am

ESP_Sprite wrote:
Sat Jan 06, 2024 11:50 am
You already found the error: the stack of the blink task overflowed because it has too little stack memory. In the xTaskCreate(&blink_task, "blink_task", 1024, NULL, 5, NULL); line, increase the 1024 to something higher, e.g. 8192.
Thank you

Who is online

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