From 0ac788f66616dd687bc440a2b3a8a8f15839f013 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sun, 16 Aug 2020 17:52:09 +0300 Subject: [PATCH] Add option to select the core used for Arduino and it's events --- boards.txt | 14 ++++++++++++++ cores/esp32/HardwareSerial.h | 3 +++ cores/esp32/esp32-hal.h | 8 ++++++++ cores/esp32/main.cpp | 2 +- libraries/WiFi/src/WiFiGeneric.cpp | 4 ++-- platform.txt | 4 +++- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/boards.txt b/boards.txt index 3fc656dc..52583d81 100644 --- a/boards.txt +++ b/boards.txt @@ -9,6 +9,8 @@ menu.PartitionScheme=Partition Scheme menu.DebugLevel=Core Debug Level menu.PSRAM=PSRAM menu.Revision=Board Revision +menu.LoopCore=Arduino Runs On +menu.EventsCore=Events Run On ############################################################## ### DO NOT PUT BOARDS ABOVE THE OFFICIAL ESPRESSIF BOARDS! ### @@ -194,6 +196,8 @@ esp32.build.flash_mode=dio esp32.build.boot=dio esp32.build.partitions=default esp32.build.defines= +esp32.build.loop_core= +esp32.build.event_core= esp32.menu.PSRAM.disabled=Disabled esp32.menu.PSRAM.disabled.build.defines= @@ -295,6 +299,16 @@ esp32.menu.UploadSpeed.460800.upload.speed=460800 esp32.menu.UploadSpeed.512000.windows=512000 esp32.menu.UploadSpeed.512000.upload.speed=512000 +esp32.menu.LoopCore.1=Core 1 +esp32.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32.menu.LoopCore.0=Core 0 +esp32.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +esp32.menu.EventsCore.1=Core 1 +esp32.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +esp32.menu.EventsCore.0=Core 0 +esp32.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + esp32.menu.DebugLevel.none=None esp32.menu.DebugLevel.none.build.code_debug=0 esp32.menu.DebugLevel.error=Error diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 5172a3c1..ec66accf 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -113,6 +113,9 @@ protected: extern void serialEventRun(void) __attribute__((weak)); #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) +#ifndef ARDUINO_SERIAL_PORT +#define ARDUINO_SERIAL_PORT 0 +#endif #if ARDUINO_SERIAL_PORT //Serial used for USB CDC #include "USB.h" #include "USBCDC.h" diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index 2f84e453..b22e5922 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -52,6 +52,14 @@ extern "C" { #define ARDUINO_ISR_FLAG (0) #endif +#ifndef ARDUINO_RUNNING_CORE +#define ARDUINO_RUNNING_CORE CONFIG_ARDUINO_RUNNING_CORE +#endif + +#ifndef ARDUINO_EVENT_RUNNING_CORE +#define ARDUINO_EVENT_RUNNING_CORE CONFIG_ARDUINO_EVENT_RUNNING_CORE +#endif + //forward declaration from freertos/portmacro.h void vPortYield(void); void yield(void); diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 8f6a7a1e..ba41e0fd 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -44,7 +44,7 @@ extern "C" void app_main() #endif loopTaskWDTEnabled = false; initArduino(); - xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE); + xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE); } #endif diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index e2d2b5ab..f1d0cfac 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -45,7 +45,7 @@ extern "C" { } //extern "C" -#include "esp32-hal-log.h" +#include "esp32-hal.h" #include #include "sdkconfig.h" @@ -475,7 +475,7 @@ static bool _start_network_event_task(){ } if(!_arduino_event_task_handle){ - xTaskCreateUniversal(_arduino_event_task, "arduino_events", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, CONFIG_ARDUINO_EVENT_RUNNING_CORE); + xTaskCreateUniversal(_arduino_event_task, "arduino_events", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE); if(!_arduino_event_task_handle){ log_e("Network Event Task Start Failed!"); return false; diff --git a/platform.txt b/platform.txt index c4e670ed..8607c693 100644 --- a/platform.txt +++ b/platform.txt @@ -90,7 +90,9 @@ build.flash_mode=dio build.boot=bootloader build.code_debug=0 build.defines= -build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug} {build.defines} {build.extra_flags.{build.mcu}} +build.loop_core= +build.event_core= +build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug} {build.loop_core} {build.event_core} {build.defines} {build.extra_flags.{build.mcu}} # Check if custom partitions exist recipe.hooks.prebuild.1.pattern=bash -c "[ ! -f {build.source.path}/partitions.csv ] || cp -f {build.source.path}/partitions.csv {build.path}/partitions.csv"