TaskHandle_t, and passing object causing crash when using object

uneasy
Posts: 2
Joined: Wed Feb 08, 2023 10:27 pm

TaskHandle_t, and passing object causing crash when using object

Postby uneasy » Thu Mar 09, 2023 7:23 pm

It's probably user error, but I can't figure out how to properly pass created object to task, so it can be used along with other tasks.
Here is bit of code when I am creating a task and passing an object

Code: Select all

LinHandler lin;
TaskHandle_t Task1;
void loop2(void* parameter) {
    LinHandler& lin = *((LinHandler*)parameter);
    for (;;) {
        lin.write();  // Write data to LIN
        delay(100);
    }
}

void setup() {
  // Initialize your task (2nd loop)
    xTaskCreatePinnedToCore(
        loop2,        // name of the task function
        "ledCheck",   // name of the task
        1000,         // memory assigned for the task
        (void*)&lin,  // parameter to pass if any
        1,            // priority of task, starting from 0(Highestpriority) *IMPORTANT*( if set to 1 and there is no activity in your 2nd loop, it will reset the esp32)
        &Task1,       // Reference name of taskHandle variable
        0); 
}
Outside task, `lin.write()` works just fine, but when it's inside the task, it crashed esp on execution. So My assumption is I am not actually passing proper reference ?

And just for reference, inside my object that's how I initialize it

Code: Select all

private:
 lin_bus _lin = lin_bus(LIN_SERIAL, LIN_V2, LIN_EN, LIN_WK, LIN_TX);
and `_lin.write` is what's causing the crash.

What I am doing wrong ?

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

Re: TaskHandle_t, and passing object causing crash when using object

Postby ESP_Sprite » Fri Mar 10, 2023 1:03 am

Just to check, after the task initialized, you *only* do things with the lin object within that task? If not, the issue may be that that driver isn't properly re-entrant.

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: TaskHandle_t, and passing object causing crash when using object

Postby boarchuz » Fri Mar 10, 2023 9:04 am

1000 bytes is a very low stack size. Try 4096.

Side note: The comment on priority is wrong (0 is lowest)

Who is online

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