The ESP32 is multicore. The task scheduler will use whichever core is available to run a time slice for your task. If you'd rather this only ran on a single core you can use xTaskCreatePinnedToCore to ensure that it will only be run on that particular core. The underlying system utilizes this to run certain tasks (like Wi-Fi) on just one core leaving the other core free for user programs. Answer from MrSurly on reddit.com
🌐
Espressif
docs.espressif.com › projects › esp-idf › en › v4.3 › esp32 › api-reference › system › freertos.html
FreeRTOS - ESP32 - — ESP-IDF Programming Guide v4.3 documentation
BaseType_t xTaskCreatePinnedToCore(TaskFunction_t pvTaskCode, const char *const pcName, const uint32_t usStackDepth, void *const pvParameters, UBaseType_t uxPriority, TaskHandle_t *const pvCreatedTask, const BaseType_t xCoreID)¶
🌐
Reddit
reddit.com › r/esp32 › what is difference between xtaskcreatepinnedtocore and xtaskcreate ?
r/esp32 on Reddit: what is difference between xTaskCreatePinnedToCore and xTaskCreate ?
June 25, 2022 -

I just started with freertos example in arduino on ESP32, i noticed that most of exmaple have xTaskCreatePinnedToCore used to create task. This DHT sensor lib als0 uses xTaskCreatePinnedToCore . i would like to know difference between xTaskCreatePinnedToCore and xTaskCreate ? Which should be used ? how does it effects working if i have multiple task ?

Discussions

ESP32 xTaskCreatePinnedToCore usage in a class
Hi there, straight to the point. I'm trying to use wificlientsecure to make some https requests, I want these requests to run on the esp32's second core, so they're not blocking the main thread. But I've run into some problems trying to put the following sketch into a class. More on forum.arduino.cc
🌐 forum.arduino.cc
1
0
January 10, 2020
[usb_device_uac] assert failed: xTaskCreatePinnedToCore freertos_tasks_c_additions.h (AEGHB-674)
Answers checklist. I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there. I have updated my IDF branch (master or release) to the latest version and checked t... More on github.com
🌐 github.com
2
June 4, 2024
Why was xTaskCreatePinnedToCore removed from the latest release?
Am I not mistaken that the xTaskCreatePinnedToCore functionalities were removed in the newest release? The functions are still provided to me via my MPU vendor but in an additional header file. What was the issue? More on forums.freertos.org
🌐 forums.freertos.org
4
0
September 5, 2022
Programing error, xTaskCreatePinnedToCore + was not declared in this scope
Hello everyone! Plese help me! I have problem with 2 core programming esp32 wroom 32d. Arduino ide compiles code, but PlatformIO does’t work and say ‘task1code’ was not declared in this scope and ‘task2code’ was not declared in this scope. Code here: #include #include TaskHandle_t ... More on community.platformio.org
🌐 community.platformio.org
0
0
May 13, 2021
🌐
ESP32 Forum
esp32.com › viewtopic.php
xTaskCreatePinnedToCore - task priority - ESP32 Forum
// Save compressed in memory instead of simply: uint8_t compressed[compressedBytes.size()]; receivedLength = packet.length(); compressed = (uint8_t*)malloc(receivedLength); // I would like to pass this instead of assigning it globally for ( int i = 0; i < packet.length(); i++ ) { uint8_t conv = (int) packet.data()[i]; compressed[i] = conv; // Bytes read here are OK Serial.print(conv);Serial.print(","); } xTaskCreatePinnedToCore( brTask, /* Task function.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
ESP32 xTaskCreatePinnedToCore usage in a class - Programming - Arduino Forum
January 10, 2020 - Hi there, straight to the point. I'm trying to use wificlientsecure to make some https requests, I want these requests to run on the esp32's second core, so they're not blocking the main thread. But I've run into some problems trying to put the following sketch into a class.
🌐
GitHub
github.com › espressif › esp-iot-solution › issues › 366
[usb_device_uac] assert failed: xTaskCreatePinnedToCore ...
June 4, 2024 - I (1093) sleep: Configure to isolate all GPIO pins in sleep state I (1099) sleep: Enable automatic switching of GPIO sleep configuration I (1107) main_task: Started on CPU0 I (1111) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations I (1120) main_task: Calling app_main() assert failed: xTaskCreatePinnedToCore freertos_tasks_c_additions.h:178 (( ( ( ( BaseType_t ) xCoreID ) >= 0 && ( ( BaseType_t ) xCoreID ) < 2 ) ?
Author   espressif
🌐
Wokwi
wokwi.com › projects › 364070101584258049
ESP32 FreeRTOS xTaskCreatePinnedToCore
in order to enable us to select ... Serial.println("Hello, ESP32 with FreeRTOS !"); } void loop() { // put your main code here, to run repeatedly: xTaskCreatePinnedToCore( Buzer_Task, // Function to be performed the task is called "Buzer_Task", // Name of the task in text 4096, ...
🌐
John M. Wargo
johnwargo.com › posts › 2023 › arduino-running-tasks-on-multiple-cores
Arduino ESP32 Running Tasks On Multiple Cores: John M. Wargo
August 25, 2023 - Next, the sketch uses the xTaskCreatePinnedToCore method to assign the appropriate code to the selected processor.
Find elsewhere
🌐
FreeRTOS Community
forums.freertos.org › kernel
Why was xTaskCreatePinnedToCore removed from the latest release? - Kernel - FreeRTOS Community Forums
September 5, 2022 - Am I not mistaken that the xTaskCreatePinnedToCore functionalities were removed in the newest release? The functions are still provided to me via my MPU vendor but in an additional header file. What was the issue?
🌐
PlatformIO Community
community.platformio.org › development platforms
Programing error, xTaskCreatePinnedToCore + was not declared in this scope - Development Platforms - PlatformIO Community
May 13, 2021 - Hello everyone! Plese help me! I have problem with 2 core programming esp32 wroom 32d. Arduino ide compiles code, but PlatformIO does’t work and say ‘task1code’ was not declared in this scope and ‘task2code’ was not declared in this scope. Code here: #include #include TaskHandle_t Task1, Task2; const uint8_t led1 = 2; const uint8_t led2 = 5; void setup() { Serial.begin(115200); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); ...
🌐
ESP-IDF Programming Guide
demo-dijiudu.readthedocs.io › en › latest › api-guides › freertos-smp.html
ESP-IDF FreeRTOS SMP Changes — ESP-IDF Programming Guide v3.0-dev-1474-gf8bda32 documentation
For example xTaskCreatePinnedToCore(tsk_callback, “APP_CPU Task”, 1000, NULL, 10, NULL, 1) creates a task of priority 10 that is pinned to APP_CPU with a stack size of 1000 bytes.
🌐
GitHub
github.com › espressif › esp-idf › issues › 3625
"xTaskCreatePinnedToCore" didn't work (IDFGH-1338) · Issue #3625 · espressif/esp-idf
June 13, 2019 - At the same time , I had other twos task running: xTaskCreatePinnedToCore(i2c_task, "i2c_task", 1024 * 2, (void )0, 8, NULL,tskNO_AFFINITY); xTaskCreatePinnedToCore(send_IIC, "send_IIC", 102410, NULL, 8, NULL,tskNO_AFFINITY); So, why the ball_follow_task didn't .
Author   espressif
🌐
SourceVu
sourcevu.sysprogs.com › espressif › lib › freertos › symbols › xTaskCreateStaticPinnedToCore
xTaskCreateStaticPinnedToCore() - syntax, references, call tree, description
Create a new static task that is pinned to a particular core This function is similar to xTaskCreateStatic... See references, calls, examples below.
🌐
Home Assistant
community.home-assistant.io › esphome
xTaskCreatePinnedToCore not working on ESPHome - ESPHome - Home Assistant Community
March 29, 2023 - Hello. I’m trying to run code assyncronously and, therefore, I would like to create some threads. On the Arduino IDE, I used to do xTaskCreatePinnedToCore on the setup() method. So, to replicate it, I’ve setup a CustomSensor. If I place normal code in the setup() and update() methods, it works flawlessly.
Top answer
1 of 2
2

You have created 2 tasks with priority 0 which is the lowest priority in the system. ESP IDF implicitly creates a several other tasks (many with higher priorities) and your tasks have to share CPU cores with those.

Firstly there are 2 idle tasks (one per core) with priority 0. Since the priorities of your tasks and the idle tasks are equal, they share core time equally (50/50). So the scheduler rotates them on each core every 10 ms by default, which is quite likely the source of your flickering.

Then there are other, higher priority tasks which ESP IDF creates. If you enabled WiFi then its driver runs in a high priority (23 by default) task. The High Resolution Timer service creates its own high priority (22) task. If you've enabled TCP/IP networking, this has runs in a high priority task; etc. Granted, those tasks don't take up much core time if you don't use their services. But they take up some.

So, in short you don't get exclusive use of a CPU core. You can cut out the idle tasks by raising your priority (by the way, the Task Watchdog Timer will complain and reset the system soon if you don't let the idle task run at all; unless you disable it). You can also cut out all other tasks by raising your priority to the maximum, but in any real embedded system those other tasks do something useful ;)

2 of 2
0

Might be to do with the fact that ESP32 is SMP.

https://www.freertos.org/single-core-amp-smp-rtos-scheduling.html

Not 100% sure but the Freertos task scheduler needs to run somewhere, it will only run on 1 core, subsequently stopping both tasks as it figures out what to do. So it will have to pause one of the task on a core. Without the delay then the scheduler may struggle.

This is a bit of guess. Might point you in the right direction.

🌐
Lang-ship
lang-ship.com › reference › unofficial › M5StickC › Functions › freertos › task
タスク(task) - M5StickC非公式日本語リファレンス
TaskHandle_t taskHandle; void testTask(void *pvParameters) { while (1) { // 通知が来るまで待機する。値のクリアはしないので通知が受け取れている限り1のまま int ulNotifiedValue = ulTaskNotifyTake( pdFALSE, portMAX_DELAY ); Serial.println( pcTaskGetTaskName(NULL) ); Serial.println( ulNotifiedValue ); } } void setup() { Serial.begin(115200); // Core0でタスク起動 xTaskCreatePinnedToCore( testTask, "loopTask1", 8192, NULL, 1, &taskHandle, 0 ); } void loop() { delay(500); // 通知送信(値は0から増えていき、100の値は無視される) xTaskNotify(taskHandle, 100, eIncrement ); }
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How to make tasks and determine stack size in freeRTOS? - Programming - Arduino Forum
April 7, 2022 - Hello, I don't think I'm fully understanding how to create tasks in freeRTOS. So I made a very simple scenario to help me understand the structure: I have two LEDs (red and green), I want red to turn on for 1 second, every 40 milliseconds, I want the green to turn on for 1 second, every 1000 ...
🌐
FreeRTOS Community
forums.freertos.org › kernel
Brief task suspension when using xTaskCreate - FreeRTOS on ESP32 - Kernel - FreeRTOS Community Forums
February 16, 2022 - I have boiled a problem I am having down to something really simple - a function toggling a pin high and low very quickly. If I do not use freeRTOS I get a continuous oscillation on the output pin, see photo. However if I use the code below I get output on oscilloscope (1ms/div): Approximately every 1ms, the pin does not toggle for around 1ms Here is my code: void task1(void* pvParameters) { for(;;) { digitalWrite(27, HIGH); digitalWrite(27, LOW); } } void setup() { ...
🌐
Espressif
docs.espressif.com › projects › esp-idf › en › v5.0 › esp32s3 › api-guides › performance › speed.html
Maximizing Execution Speed - ESP32-S3 - — ESP-IDF Programming Guide v5.0 documentation
As ESP-IDF FreeRTOS is a real-time operating system, it’s necessary to ensure that high throughput or low latency tasks are granted a high priority in order to run immediately. Priority is set when calling xTaskCreate() or xTaskCreatePinnedToCore() and can be changed at runtime by calling ...