FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2017 Threads]
Hello. In this code it is not possible to print correctly the data on each task. I can not understand the reason. The output of the program is below. How do I get the HELLO_WORLD string in each of the tasks in the output?
Using the parameter transfer.
Thank you.
~~~
include
include "freertos/FreeRTOS.h"
include "freertos/task.h"
include "freertos/event_groups.h"
include "esp_system.h"
include "espeventloop.h"
include "esp_log.h"
include "nvs_flash.h"
const sizet stacksize = 4096;
static void task1(void *pvParameters)
{
ESPLOGE("TASK", "TASK CORE1: %s", (char *)pvParameters);
vTaskDelete(NULL);
}
static void taskmain(void *pvParameters)
{
char *data = (char *)pvParameters;
while(1)
{
ESPLOGI("TASK", "TASK CORE0: %s", data);
vTaskDelay(1000 / portTICKRATEMS);
xTaskCreatePinnedToCore(&task1, "task1", stacksize, (void*)&data, 2, NULL, 1);
}
vTaskDelete(NULL);
}
void appmain()
{
char data[12] = "HELLOWORLD";
xTaskCreatePinnedToCore(&taskmain, "taskmain", stack_size, (void*)&data, 1, NULL, 0);
}
~~~
OUTPUT:
~~~
E (264246) TASK: TASK CORE1: ��?
I (265246) TASK: TASK CORE0:
E (265246) TASK: TASK CORE1: ��?
I (266246) TASK: TASK CORE0:
E (266246) TASK: TASK CORE1: ��?
I (267246) TASK: TASK CORE0:
E (267246) TASK: TASK CORE1: ��?
I (268246) TASK: TASK CORE0:
E (268246) TASK: TASK CORE1: ��?
I (269246) TASK: TASK CORE0:
E (269246) TASK: TASK CORE1: ��?
I (270246) TASK: TASK CORE0:
E (270246) TASK: TASK CORE_1: ��?
~~~
Probably because appmain is left and the string is a stack variable at least concerning taskmain. Be careful with the lifetime of data given by pvParameters.
Why not using a task local string ? Provided that ESP_LOGI irtself is thread-safe of course ;)
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.