Page 1 of 1
FreeRTOS Task notification crashing esp32.
Posted: Thu Jan 30, 2020 2:12 am
by Gardin
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.
Re: FreeRTOS Task notification crashing esp32.
Posted: Thu Jan 30, 2020 5:01 am
by mikemoy
Probably be better to answer the question if you posted your code.
Re: FreeRTOS Task notification crashing esp32.
Posted: Thu Jan 30, 2020 10:32 am
by Gardin
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.
Re: FreeRTOS Task notification crashing esp32.
Posted: Thu Jan 30, 2020 2:33 pm
by mikemoy
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);
Re: FreeRTOS Task notification crashing esp32.
Posted: Thu Jan 30, 2020 3:31 pm
by Gardin
Oh boy, how did I missed that!?
It's working now thanks a lot!
Re: FreeRTOS Task notification crashing esp32.
Posted: Thu Feb 04, 2021 10:37 pm
by AG1702
Help with this, please. It crashes.
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/gpio.h"
TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
void myTask1(void *pvParameter)
{
while(1)
{
xTaskNotifyGive(myTask2Handle);
vTaskDelay(1000);
}
}
void myTask2(void *pvParameter)
{
int not_value = 0;
while(1)
{
not_value = ulTaskNotifyTake( pdTRUE, (TickType_t) portMAX_DELAY );
if(not_value > 0)
{
printf("notification received: %d\r\n", not_value);
}
}
}
void app_main()
{
xTaskCreate(&myTask1, "myTask1", 2048, NULL, 1, &myTask1Handle);
xTaskCreate(&myTask2, "myTask2", 2048, NULL, 1, &myTask2Handle);
}
Re: FreeRTOS Task notification crashing esp32.
Posted: Fri Feb 05, 2021 7:41 am
by ESP_Sprite
What if in your code xTaskNotifyGive is called in task1 while the xTaskCreate of task 2 is not finished yet?