FreeRTOS Task notification crashing esp32.

Gardin
Posts: 16
Joined: Fri Dec 13, 2019 4:53 pm

FreeRTOS Task notification crashing esp32.

Postby Gardin » Thu Jan 30, 2020 2:12 am

Hello all,

I'm currently studying Tasks notifications (FreeRTOS) with the esp32, in some tests like using it as a binary semaphore I had no trouble. But when I started to try passing data around using xTaskNotify() and xTaskNotifyWait() the esp32 started to crash when printing the data

Code: Select all

Core  1 panic'ed (LoadProhibited). Exception was unhandled
. For some reason I'm getting an invalid memory location out of the xTaskNotifyWait().
At first, I thought it was because an untested FreeRTOS API, but it appears that this API is currently supported.

Is that a bug or I'm missing something?

I'm using esp-idf version v4.1-dev-2055-gf5b82c5b1-dirty

Regards,

Gardin.

mikemoy
Posts: 480
Joined: Fri Jan 12, 2018 9:10 pm

Re: FreeRTOS Task notification crashing esp32.

Postby mikemoy » Thu Jan 30, 2020 5:01 am

Probably be better to answer the question if you posted your code.

Gardin
Posts: 16
Joined: Fri Dec 13, 2019 4:53 pm

Re: FreeRTOS Task notification crashing esp32.

Postby Gardin » Thu Jan 30, 2020 10:32 am

Yes, sorry about that.

Here is the code:

Code: Select all

void task1(void *pvParameters);
void task2(void *pvParameters);

static TaskHandle_t task1_handle;
static TaskHandle_t task2_handle = NULL;



void app_main(void)
{
    xTaskCreatePinnedToCore(task1, "Task1", 1024, NULL, 1, &task1_handle, 1);
    xTaskCreatePinnedToCore(task2, "Task2", 1024, NULL, 1, &task2_handle, 1);
}


void task1(void *pvParameters)
{
    const TickType_t block_time = pdMS_TO_TICKS(10);
    uint32_t ulNotifiedValue = 0;
    uint32_t teste = 0;
    BaseType_t xResult;
    for(;;)
    {
        xResult = xTaskNotifyWait(0X00, 0x00, &ulNotifiedValue,  block_time);
        if(xResult == pdPASS)
        {
            printf("A task2 ja roudou %zu vezes. E eu sou a task1\n", ulNotifiedValue);
        }

        vTaskDelay(pdMS_TO_TICKS(250));
    }
}


void task2(void *pvParameters)
{
    static uint32_t counter = 0;
    static uint32_t counter2 = 0;
    for(;;)
    {
        counter ++;
        counter2 ++;
        if(counter == 5)
        {
            xTaskNotify(task1_handle, counter2, eSetValueWithoutOverwrite);
            printf("oi sou a task2\n");
            counter = 0;
        }
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}
It works untill I call

Code: Select all

xTaskNotify(task1_handle, counter2, eSetValueWithoutOverwrite);
after that task1 prints the received value once and crashes.

mikemoy
Posts: 480
Joined: Fri Jan 12, 2018 9:10 pm

Re: FreeRTOS Task notification crashing esp32.

Postby mikemoy » Thu Jan 30, 2020 2:33 pm

The first thing that jumps out at me is that your stack allotment is to low for using a printf.
Kick them up to at least 2048 and try it.

xTaskCreatePinnedToCore(task1, "Task1", 2048, NULL, 1, &task1_handle, 1);
xTaskCreatePinnedToCore(task2, "Task2", 2048, NULL, 1, &task2_handle, 1);

Gardin
Posts: 16
Joined: Fri Dec 13, 2019 4:53 pm

Re: FreeRTOS Task notification crashing esp32.

Postby Gardin » Thu Jan 30, 2020 3:31 pm

Oh boy, how did I missed that!?

It's working now thanks a lot!

Who is online

Users browsing this forum: No registered users and 21 guests