Page 1 of 2

Dual core

Posted: Sat Jun 10, 2017 9:58 pm
by urbanze
Hello guys! i buy esp32 and need to know how to use dual core with arduino ide. i need to create a simillar structure, like this:

void setup1()
void loop1()


void setup2()
void loop2()

how? thanks! :D

Re: Dual core

Posted: Sun Jun 11, 2017 12:41 pm
by f.h-f.s.
You will need these headers to create another task/thread on the other cpu:

Code: Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_tasks.h" 
You can call setup2() in setup().
In setup2() you can create the second loop task.

xTaskCreatePinnedToCore(loop2,"loop2", 4096, NULL, ESP_TASK_PRIO_MIN, NULL, 1); //4096 is the stacksize, last argument is the cpu(0 or 1

or create a setup2() task that calls loop2()

See arduino-esp32 https://github.com/espressif/arduino-es ... 2/main.cpp

Re: Dual core

Posted: Sun Jun 11, 2017 4:57 pm
by Ritesh
So, In short, xTaskCreatePinnedToCore is useful function for you with last argument as to create task for CPU0 or CPU1 based on your task, it's handler, size and it's priority.

As per my understanding, By default if you will directly use xTaskCreate API then it will create task for CPU1 as CPU0 is dedicated for WiFi and Bluetooth by default.

Re: Dual core

Posted: Sun Jun 11, 2017 10:05 pm
by urbanze
thanks!

if i not use this functions, the code is usually run in core 0? core 1? or in two in same time? any datasheet for this informations?

Re: Dual core

Posted: Sun Jun 11, 2017 10:39 pm
by WiFive
Ritesh wrote:As per my understanding, By default if you will directly use xTaskCreate API then it will create task for CPU1 as CPU0 is dedicated for WiFi and Bluetooth by default.
No it will create task with no affinity meaning it will run on either core, whichever is available.

Re: Dual core

Posted: Mon Jun 12, 2017 12:27 am
by Ritesh
WiFive wrote:
Ritesh wrote:As per my understanding, By default if you will directly use xTaskCreate API then it will create task for CPU1 as CPU0 is dedicated for WiFi and Bluetooth by default.
No it will create task with no affinity meaning it will run on either core, whichever is available.
Ok. But WiFi and Bluetooth Core is CPU0 for dedicated purpose. Correct?

Re: Dual core

Posted: Mon Jun 12, 2017 1:44 am
by urbanze
WiFive wrote:
Ritesh wrote:As per my understanding, By default if you will directly use xTaskCreate API then it will create task for CPU1 as CPU0 is dedicated for WiFi and Bluetooth by default.
No it will create task with no affinity meaning it will run on either core, whichever is available.
and, if i want to call a X function in core 1, i need to call this function in corr 0, but, if code is slowly in core 0, this affect core 1 functionz?

Re: Dual core

Posted: Mon Jun 12, 2017 3:28 am
by kolban
@urbanze,
A question if I may. Do you really need "dual core" or do you need "multi task"?

What is the nature of your solution where you think you need to harness the power of dual core processors as opposed to a potential logical design where your design calls for multi-tasking?

You can run multiple parallel loops with multi-tasking that don't involve multi-core. I'd like to hear your use case that calls for true dual core support?

Re: Dual core

Posted: Mon Jun 12, 2017 4:08 am
by Ritesh
urbanze wrote:thanks!

if i not use this functions, the code is usually run in core 0? core 1? or in two in same time? any datasheet for this informations?
Hi,

If you have looked into make menuconfig configurations for your application then there is one options defined into configuration like "[*] Run FreeRTOS only on first core" in freeRTOS section in which you can explicitly execute freeRTOS stuffs (like Tasks, Queues and other stuffs) into CPU0 core.

If you will not use this function and also not select above configuration from make menuconfig configuration then whatever task you have created might be executed either on core 0 or core 1 which is dependent on stack availability.

Re: Dual core

Posted: Mon Jun 12, 2017 2:34 pm
by urbanze
Ritesh wrote:
urbanze wrote:thanks!

if i not use this functions, the code is usually run in core 0? core 1? or in two in same time? any datasheet for this informations?
Hi,

If you have looked into make menuconfig configurations for your application then there is one options defined into configuration like "[*] Run FreeRTOS only on first core" in freeRTOS section in which you can explicitly execute freeRTOS stuffs (like Tasks, Queues and other stuffs) into CPU0 core.

If you will not use this function and also not select above configuration from make menuconfig configuration then whatever task you have created might be executed either on core 0 or core 1 which is dependent on stack availability.
no, i possible never really need dual core, BUT, i like to make benchmark's and compare mcu's,etc.. in my home automation, i have +10 sensor's and 2 hmi interface, dual core could help me.