Dual core

User avatar
urbanze
Posts: 270
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Dual core

Postby urbanze » Sat Jun 10, 2017 9:58 pm

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

f.h-f.s.
Posts: 208
Joined: Thu Dec 08, 2016 2:53 pm

Re: Dual core

Postby f.h-f.s. » Sun Jun 11, 2017 12:41 pm

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

Ritesh
Posts: 1167
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Dual core

Postby Ritesh » Sun Jun 11, 2017 4:57 pm

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.
Regards,
Ritesh Prajapati

User avatar
urbanze
Posts: 270
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Dual core

Postby urbanze » Sun Jun 11, 2017 10:05 pm

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?

WiFive
Posts: 2978
Joined: Tue Dec 01, 2015 7:35 am

Re: Dual core

Postby WiFive » Sun Jun 11, 2017 10:39 pm

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.

Ritesh
Posts: 1167
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Dual core

Postby Ritesh » Mon Jun 12, 2017 12:27 am

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?
Regards,
Ritesh Prajapati

User avatar
urbanze
Posts: 270
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Dual core

Postby urbanze » Mon Jun 12, 2017 1:44 am

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?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Dual core

Postby kolban » Mon Jun 12, 2017 3:28 am

@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?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Ritesh
Posts: 1167
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Dual core

Postby Ritesh » Mon Jun 12, 2017 4:08 am

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.
Regards,
Ritesh Prajapati

User avatar
urbanze
Posts: 270
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Dual core

Postby urbanze » Mon Jun 12, 2017 2:34 pm

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.

Who is online

Users browsing this forum: No registered users and 38 guests