Multiple Tasks on ESP32 with Arduino

gailu96
Posts: 9
Joined: Sat Aug 10, 2024 6:06 pm

Multiple Tasks on ESP32 with Arduino

Postby gailu96 » Thu Aug 15, 2024 4:04 pm

Hi Experts,

I am moving from ESP8266 NONOS SDK to ESP32 with Arduino and learning it slowly. I am trying to create 2 tasks running in parallel. Tasks gets created execute first loop and then ESP crashes. I am attaching my simple code and Crash logs. Can someone please let me know what is wrong with the below code causing ESP crash and reboot.

Here is the code

Code: Select all

/*
   Task
 */

#include <Arduino.h>

void writeTask(void *parameter);
void readTask(void *parameter);

void setup() {
    Serial.begin(115200);

    xTaskCreate(
        writeTask,      // Function name of the task
        "Write Count",   // Name of the task (e.g. for debugging)
        2048,        // Stack size (bytes)
        NULL,        // Parameter to pass
        1,           // Task priority
        NULL         // Task handle
    );
    xTaskCreate(
        readTask,     // Function name of the task
        "Read Count",  // Name of the task (e.g. for debugging)
        2048,       // Stack size (bytes)
        NULL,       // Parameter to pass
        1,          // Task priority
        NULL        // Task handle
    );
}

void writeTask(void *parameter) {
    int i;
    for (i=0; i<100; i++);
    {
        Serial.print("Writing Task\r\n");
        delay(1000);
    }
}
void readTask(void *parameter) {
    int i;
    for (i=0; i<100; i++);
    {
        Serial.print("Read Task\r\n");
        delay(1000);
    }
}

void loop() {

}
Serial Logs:

Code: Select all

Writing Task
Read Task
Guru Meditation Error: Core  0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d1294: 65e8a3a2 f01d0084 b1004136
Core  0 register dump:
PC      : 0x400d129a  PS      : 0x00060a30  A0      : 0x00000000  A1      : 0x3ffb91a0
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000000
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x800d129a  A9      : 0x3ffb9180
A10     : 0x000003e8  A11     : 0x3f400120  A12     : 0x00000014  A13     : 0x00000000
A14     : 0x3ffb8188  A15     : 0x80000001  SAR     : 0x00000000  EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000  LBEG    : 0x400862c1  LEND    : 0x400862d1  LCOUNT  : 0xfffffffc


Backtrace: 0x400d1297:0x3ffb91a0




ELF file SHA256: d86aa41a4e82bc60

E (1234) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0
Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_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:6940
ho 0 tail 12 room 4
load:0x40078000,len:15500
load:0x40080400,len:3844
entry 0x4008064c
...

gailu96
Posts: 9
Joined: Sat Aug 10, 2024 6:06 pm

Re: Multiple Tasks on ESP32 with Arduino

Postby gailu96 » Thu Aug 15, 2024 4:56 pm

Please ignore this post. I found the bug.

Bug is semicolon at the end of for loop. My bad.

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Multiple Tasks on ESP32 with Arduino

Postby MicroController » Thu Aug 15, 2024 7:48 pm

Note that a task function must not return.
A task needs to either run an infinite loop, or terminate itself via vTaskDelete(NULL) at some point.

Who is online

Users browsing this forum: Baidu [Spider] and 101 guests