Skip to content

Commit 880fc0b

Browse files
committed
Add option to select the core used for Arduino and it's events
1 parent 9eaa587 commit 880fc0b

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

boards.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ menu.PartitionScheme=Partition Scheme
99
menu.DebugLevel=Core Debug Level
1010
menu.PSRAM=PSRAM
1111
menu.Revision=Board Revision
12+
menu.LoopCore=Arduino Runs On
13+
menu.EventsCore=Events Run On
1214

1315
##############################################################
1416
### DO NOT PUT BOARDS ABOVE THE OFFICIAL ESPRESSIF BOARDS! ###
@@ -194,6 +196,8 @@ esp32.build.flash_mode=dio
194196
esp32.build.boot=dio
195197
esp32.build.partitions=default
196198
esp32.build.defines=
199+
esp32.build.loop_core=
200+
esp32.build.event_core=
197201

198202
esp32.menu.PSRAM.disabled=Disabled
199203
esp32.menu.PSRAM.disabled.build.defines=
@@ -295,6 +299,16 @@ esp32.menu.UploadSpeed.460800.upload.speed=460800
295299
esp32.menu.UploadSpeed.512000.windows=512000
296300
esp32.menu.UploadSpeed.512000.upload.speed=512000
297301

302+
esp32.menu.LoopCore.1=Core 1
303+
esp32.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1
304+
esp32.menu.LoopCore.0=Core 0
305+
esp32.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0
306+
307+
esp32.menu.EventsCore.1=Core 1
308+
esp32.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1
309+
esp32.menu.EventsCore.0=Core 0
310+
esp32.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0
311+
298312
esp32.menu.DebugLevel.none=None
299313
esp32.menu.DebugLevel.none.build.code_debug=0
300314
esp32.menu.DebugLevel.error=Error

cores/esp32/HardwareSerial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class HardwareSerial: public Stream
109109
extern void serialEventRun(void) __attribute__((weak));
110110

111111
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
112+
#ifndef ARDUINO_SERIAL_PORT
113+
#define ARDUINO_SERIAL_PORT 0
114+
#endif
112115
#if ARDUINO_SERIAL_PORT //Serial used for USB CDC
113116
#include "USB.h"
114117
#include "USBCDC.h"

cores/esp32/esp32-hal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ extern "C" {
5252
#define ARDUINO_ISR_FLAG (0)
5353
#endif
5454

55+
#ifndef ARDUINO_RUNNING_CORE
56+
#define ARDUINO_RUNNING_CORE CONFIG_ARDUINO_RUNNING_CORE
57+
#endif
58+
59+
#ifndef ARDUINO_EVENT_RUNNING_CORE
60+
#define ARDUINO_EVENT_RUNNING_CORE CONFIG_ARDUINO_EVENT_RUNNING_CORE
61+
#endif
62+
5563
//forward declaration from freertos/portmacro.h
5664
void vPortYield(void);
5765
void yield(void);

cores/esp32/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern "C" void app_main()
4444
#endif
4545
loopTaskWDTEnabled = false;
4646
initArduino();
47-
xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);
47+
xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE);
4848
}
4949

5050
#endif

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern "C" {
4545

4646
} //extern "C"
4747

48-
#include "esp32-hal-log.h"
48+
#include "esp32-hal.h"
4949
#include <vector>
5050
#include "sdkconfig.h"
5151

@@ -475,7 +475,7 @@ static bool _start_network_event_task(){
475475
}
476476

477477
if(!_arduino_event_task_handle){
478-
xTaskCreateUniversal(_arduino_event_task, "arduino_events", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, CONFIG_ARDUINO_EVENT_RUNNING_CORE);
478+
xTaskCreateUniversal(_arduino_event_task, "arduino_events", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE);
479479
if(!_arduino_event_task_handle){
480480
log_e("Network Event Task Start Failed!");
481481
return false;

platform.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ build.flash_mode=dio
8989
build.boot=bootloader
9090
build.code_debug=0
9191
build.defines=
92-
build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug} {build.defines} {build.extra_flags.{build.mcu}}
92+
build.loop_core=
93+
build.event_core=
94+
build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug} {build.loop_core} {build.event_core} {build.defines} {build.extra_flags.{build.mcu}}
9395

9496
# Check if custom partitions exist
9597
recipe.hooks.prebuild.1.pattern=bash -c "[ ! -f {build.source.path}/partitions.csv ] || cp -f {build.source.path}/partitions.csv {build.path}/partitions.csv"

0 commit comments

Comments
 (0)