cesp32freertosarduino-esp32

(ESP-32) Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled


I'm using a ESP32 microcontroller to run a FreeRTOS simple program of printing what is in a global variable to the serial monitor. I'm also using the Arduino IDE.

Here's the simulator that I'm using and my specific project: https://wokwi.com/projects/403426133978368001

For some reason I'm getting an error of a program that is this basic.

Here is my code:

#if CONFIG_FREERTOS_UNICORE //this will return false (reading from config in freertos.h file), so we’ll set it to run on the second core app_cpu=1
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif


//global variable
char buffer[] = "Mary had a little lamb";

//task1
void Task1_Function( void *params)
{
  uint8_t i = 0;
  uint8_t msg_len = strlen(buffer);
  
  //read (print) whatever is in the buffer
  Serial.print("Task1: ");
  for(int i; i < msg_len; i++)
  {
    Serial.print(buffer[i]);
  }
  Serial.println();
  vTaskDelay(1000 / portTICK_PERIOD_MS);

}


//task2
//void Task1_Function( void *params)
//{


//}


void setup() 
{
  
  //Initialize Serial monitor
  Serial.begin(9600);

  BaseType_t status;
  TaskHandle_t task1_handler, task2_handler;

  
  //Task 1 Creation 
  status = xTaskCreatePinnedToCore(Task1_Function,
                       "Task-1-Function",
                       1024,  //This is stack size in words, in bytes for a 32bit miccrocontroller each word is 4 bytes. so 500*4 = 20000 bytes
                       NULL,  //no parameters passed
                       1,     //priority
                       &task1_handler,
                       app_cpu
                       );

  //check if task creation, memory allocation was sucessfull
  if (status != pdTRUE)
  {
    Serial.println("Error Task1 creation failed");     //using Arduino IDE
  }
  //Or you can use the assert
  //configASSERT(status == pdTRUE);

}


void loop() 
{
  // put your main code here, to run repeatedly:
  
}

I'm getting the following error:

rst:0x1 (POWERON_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:1156
load:0x40078000,len:11456
ho 0 tail 12 room 4
load:0x40080400,len:2972
entry 0x400805dc
Task1: Mary had a little lamb
Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d1428: 4ce5e8a3 00f01db8 b2808430
Core  1 register dump:
PC      : 0x400d142d  PS      : 0x00060b30  A0      : 0x00000000  A1      : 0x3ffb8d10  
A2      : 0x3ffc1058  A3      : 0x00000016  A4      : 0x3ffbdb60  A5      : 0x00000016  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x800d142d  A9      : 

Any help is greatly appreciated


Solution

  • The problem is that your task is simply returning. That's not allowed. Most tasks are expected to live forever. If you have a task with a limited lifetime, then you have to call vTaskDelete(NULL) to allow the operating system to clean up its internal tables.

    https://www.freertos.org/implementing-a-FreeRTOS-task.html