ERROR when trying to use multiple cores

NuttyMonk
Posts: 8
Joined: Mon Jun 06, 2022 6:04 pm

ERROR when trying to use multiple cores

Postby NuttyMonk » Sun Jul 31, 2022 7:13 pm

Hi all,

i am trying to get used to using both of the cores in the PICO and am getting this error message.

Code: Select all

Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400ebf1c: 00000090 1d004136 000000f0
Core  1 register dump:
PC      : 0x400ebf23  PS      : 0x00050030  A0      : 0x00000000  A1      : 0x3ffb9470  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x00000000  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000014  A13     : 0x00000004  
A14     : 0x3ffb950c  A15     : 0x80000001  SAR     : 0x00000000  EXCCAUSE: 0x00000000  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace:0x400ebf20:0x3ffb9470

ELF file SHA256: 0000000000000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:12812
load:0x40080400,len:3032
entry 0x400805e4
This is the code i am using. The blinking LED is just my way of knowing the sketch loaded ok to the PICO.

Code: Select all

#define LED_PIN (G25)

// create tasks for specific cores
TaskHandle_t Task1;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  delay(1000);

  Serial.println("================");
  Serial.println("CODE_TESTING");
  Serial.println("================");
  Serial.println("ESP32_PICO");
  Serial.println("================");
  Serial.println("TIMERS_AND_CORES");
  Serial.println("================");

  delay(1000);

  pinMode(LED_PIN, OUTPUT);

  //create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
  xTaskCreatePinnedToCore(
                    startInputTimer,   /* Task function. */
                    "Task1",     /* name of task. */
                    1000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    2,           /* priority of the task */
                    &Task1,      /* Task handle to keep track of created task */
                    1);          /* pin task to core 0 */                  
  delay(500);
}

void startInputTimer(void * pvParameters)
{

}

void loop()
{
  digitalWrite(LED_PIN, HIGH);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  delay(1000);
}
Can anyone explain what i have done wrong to get this error message? I am basing the code on several examples i found online. The PICO just keeps resetting about once every second. I was running more code to find the error but pared it down to what i am posting here and it seems to be happening due to the xTaskCreatePinnedToCore() function.

Cheers

NM

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

Re: ERROR when trying to use multiple cores

Postby ESP_Sprite » Mon Aug 01, 2022 1:57 am

Task functions should not ever return. Either they should exit by deleting their task (using vTaskDelete(NULL)) or they should loop forever (but make sure there's something blocking, like vTaskDelay() or delay() in the loop or the watchdog will get angry)

NuttyMonk
Posts: 8
Joined: Mon Jun 06, 2022 6:04 pm

Re: ERROR when trying to use multiple cores

Postby NuttyMonk » Mon Aug 01, 2022 3:21 am

Thanks Sprite,

that was very helpful and i got it working now.

Is it possible to start a timer in the Task1 startInputTimer() function and then delete the Task1 task, but the timer will run on the core it is assigned to in the task before it was deleted?

Thanks for your help.

NM

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

Re: ERROR when trying to use multiple cores

Postby ESP_Sprite » Mon Aug 01, 2022 6:29 am

It'll certainly work OK, as in the timer will start and nothing will crash, but if the timer runs on the same core as the task depends on what type of timer you use. FreeRTOS and esp_timer timers actually run and call the callbacks in their own tasks, so they run where that task runs, independent of where you start the timer. Actual hardware timers do call their interrupt on the core you initialize them (or more specifically: the core that runs the task that allocates the interrupt) on.

NuttyMonk
Posts: 8
Joined: Mon Jun 06, 2022 6:04 pm

Re: ERROR when trying to use multiple cores

Postby NuttyMonk » Mon Aug 01, 2022 3:29 pm

I tried that and it worked! Here is my final code for creating a hardware timer to run on a specific core and then deleting the task after the timer is created. The timer keeps on running on the core it was created on.

Code: Select all

volatile int interruptCounter;
 
hw_timer_t * timer = NULL;
 
#define LED_PIN (G25)

// task to create the timer on a specific core
TaskHandle_t Task1;

void IRAM_ATTR onTimer() {
  interruptCounter++;

  Serial.print("An interrupt has occurred. Total number: ");
  Serial.println(interruptCounter);
  Serial.print("onTimer running on core ");
  Serial.println(xPortGetCoreID());
  Serial.println();
}

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  delay(1000);

  Serial.println("================");
  Serial.println("CODE_TESTING");
  Serial.println("================");
  Serial.println("ESP32_PICO");
  Serial.println("================");
  Serial.println("TIMERS_AND_CORES");
  Serial.println("================");

  delay(1000);

  pinMode(LED_PIN, OUTPUT);

  //create a task that will be executed in the vTaskFunction() function, with priority 2 and executed on core 0
  xTaskCreatePinnedToCore(
                    vTaskFunction,   /* Task function. */
                    "Task1",     /* name of task. */
                    10000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    2,           /* priority of the task */
                    &Task1,      /* Task handle to keep track of created task */
                    0);          /* pin task to core 0 */                  
  delay(500);
}

// Create the timer then delete the task that created it
void vTaskFunction( void * pvParameters )
{
  Serial.print("vTaskFunction running on core ");
  Serial.println(xPortGetCoreID());

  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmWrite(timer, 1000000, true);
  timerAlarmEnable(timer);
  
  // delete this task
  vTaskDelete( Task1 );
}

void loop()
{
// blink LED to show code has uploaded ok
  digitalWrite(LED_PIN, HIGH);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  delay(1000);
}
Thanks Sprite!!!

Cheers

NM

Who is online

Users browsing this forum: No registered users and 40 guests