From 6389d64f9cd524c2d8d27d041091bcd647333c9b Mon Sep 17 00:00:00 2001 From: Gonzalo Brusco Date: Wed, 4 May 2022 09:16:50 -0300 Subject: [PATCH 1/6] Adjustable Serial Event Task Stack Size And Priority --- cores/esp32/HardwareSerial.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 323482a6bbf..ac391b44d09 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -9,6 +9,14 @@ #include "driver/uart.h" #include "freertos/queue.h" +#ifndef ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE +#define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048 +#endif + +#ifndef ARDUINO_SERIAL_EVENT_TASK_PRIORITY +#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES-1) +#endif + #ifndef SOC_RX0 #if CONFIG_IDF_TARGET_ESP32 #define SOC_RX0 3 @@ -159,7 +167,7 @@ HardwareSerial::~HardwareSerial() void HardwareSerial::_createEventTask(void *args) { // Creating UART event Task - xTaskCreate(_uartEventTask, "uart_event_task", 2048, this, configMAX_PRIORITIES - 1, &_eventTask); + xTaskCreate(_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask); if (_eventTask == NULL) { log_e(" -- UART%d Event Task not Created!", _uart_nr); } From db57d137be057de5fb6cf87991a0803ae53116a5 Mon Sep 17 00:00:00 2001 From: Gonzalo Brusco Date: Wed, 4 May 2022 16:06:38 -0300 Subject: [PATCH 2/6] Added options to Kconfig --- Kconfig.projbuild | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 0e9c628f138..5401a914568 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -82,6 +82,18 @@ choice ARDUINO_UDP_RUNNING_CORE endchoice +config ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE + int "Serial Event task stack size" + default 2048 + help + Amount of stack available for the Serial Event task. + +config ARDUINO_SERIAL_EVENT_TASK_PRIORITY + int "Priority of the Serial Event task" + default 24 + help + Select at what priority you want the Serial Event task to run. + config ARDUINO_UDP_TASK_PRIORITY int "Priority of the UDP task" default 3 From 8d1de723b8af2d8755afa7f2b32dba79666a3b47 Mon Sep 17 00:00:00 2001 From: Gonzalo Brusco Date: Wed, 4 May 2022 20:31:14 -0300 Subject: [PATCH 3/6] Added Core Affinity --- Kconfig.projbuild | 21 +++++++++++++++++++++ cores/esp32/HardwareSerial.cpp | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 5401a914568..f7652e93a78 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -82,6 +82,27 @@ choice ARDUINO_UDP_RUNNING_CORE endchoice +choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE + bool "Core on which Arduino's Serial Event task is running" + default ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY + help + Select on which core Arduino's Serial Event task run + + config ARDUINO_SERIAL_EVENT_RUN_CORE0 + bool "CORE 0" + config ARDUINO_SERIAL_EVENT_RUN_CORE1 + bool "CORE 1" + config ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY + bool "BOTH" + +endchoice + +config ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE + int + default 0 if ARDUINO_SERIAL_EVENT_RUN_CORE0 + default 1 if ARDUINO_SERIAL_EVENT_RUN_CORE1 + default -1 if ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY + config ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE int "Serial Event task stack size" default 2048 diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index ac391b44d09..acc1bd2c88b 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -17,6 +17,10 @@ #define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES-1) #endif +#ifndef ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE +#define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1 +#endif + #ifndef SOC_RX0 #if CONFIG_IDF_TARGET_ESP32 #define SOC_RX0 3 @@ -167,7 +171,7 @@ HardwareSerial::~HardwareSerial() void HardwareSerial::_createEventTask(void *args) { // Creating UART event Task - xTaskCreate(_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask); + xTaskCreateUniversal(_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask, ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE); if (_eventTask == NULL) { log_e(" -- UART%d Event Task not Created!", _uart_nr); } From 05052af0e5634eb50376ad3053bc510d4d2522ad Mon Sep 17 00:00:00 2001 From: Gonzalo Brusco Date: Fri, 6 May 2022 08:47:09 -0300 Subject: [PATCH 4/6] Added CONFIG_FREERTOS_UNICORE --- Kconfig.projbuild | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index f7652e93a78..b592271744b 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -31,6 +31,7 @@ choice ARDUINO_RUNNING_CORE bool "CORE 1" config ARDUINO_RUN_NO_AFFINITY bool "BOTH" + depends on !CONFIG_FREERTOS_UNICORE endchoice @@ -58,6 +59,7 @@ choice ARDUINO_EVENT_RUNNING_CORE bool "CORE 1" config ARDUINO_EVENT_RUN_NO_AFFINITY bool "BOTH" + depends on !CONFIG_FREERTOS_UNICORE endchoice @@ -67,21 +69,6 @@ config ARDUINO_EVENT_RUNNING_CORE default 1 if ARDUINO_EVENT_RUN_CORE1 default -1 if ARDUINO_EVENT_RUN_NO_AFFINITY -choice ARDUINO_UDP_RUNNING_CORE - bool "Core on which Arduino's UDP is running" - default ARDUINO_UDP_RUN_CORE1 - help - Select on which core Arduino's UDP run - - config ARDUINO_UDP_RUN_CORE0 - bool "CORE 0" - config ARDUINO_UDP_RUN_CORE1 - bool "CORE 1" - config ARDUINO_UDP_RUN_NO_AFFINITY - bool "BOTH" - -endchoice - choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE bool "Core on which Arduino's Serial Event task is running" default ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY @@ -94,6 +81,7 @@ choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE bool "CORE 1" config ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY bool "BOTH" + depends on !CONFIG_FREERTOS_UNICORE endchoice @@ -121,6 +109,22 @@ config ARDUINO_UDP_TASK_PRIORITY help Select at what priority you want the UDP task to run. +choice ARDUINO_UDP_RUNNING_CORE + bool "Core on which Arduino's UDP is running" + default ARDUINO_UDP_RUN_CORE1 + help + Select on which core Arduino's UDP run + + config ARDUINO_UDP_RUN_CORE0 + bool "CORE 0" + config ARDUINO_UDP_RUN_CORE1 + bool "CORE 1" + config ARDUINO_UDP_RUN_NO_AFFINITY + bool "BOTH" + depends on !CONFIG_FREERTOS_UNICORE + +endchoice + config ARDUINO_UDP_RUNNING_CORE int default 0 if ARDUINO_UDP_RUN_CORE0 From 0872884ea8103809ca74d2ae7a8c5b131e32f9e4 Mon Sep 17 00:00:00 2001 From: Gonzalo Brusco Date: Fri, 6 May 2022 09:33:19 -0300 Subject: [PATCH 5/6] Removed _CONFIG from FREERTOS_UNICORE --- Kconfig.projbuild | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index b592271744b..ad43d789937 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -31,7 +31,7 @@ choice ARDUINO_RUNNING_CORE bool "CORE 1" config ARDUINO_RUN_NO_AFFINITY bool "BOTH" - depends on !CONFIG_FREERTOS_UNICORE + depends on !FREERTOS_UNICORE endchoice @@ -59,7 +59,7 @@ choice ARDUINO_EVENT_RUNNING_CORE bool "CORE 1" config ARDUINO_EVENT_RUN_NO_AFFINITY bool "BOTH" - depends on !CONFIG_FREERTOS_UNICORE + depends on !FREERTOS_UNICORE endchoice @@ -81,7 +81,7 @@ choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE bool "CORE 1" config ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY bool "BOTH" - depends on !CONFIG_FREERTOS_UNICORE + depends on !FREERTOS_UNICORE endchoice @@ -121,7 +121,7 @@ choice ARDUINO_UDP_RUNNING_CORE bool "CORE 1" config ARDUINO_UDP_RUN_NO_AFFINITY bool "BOTH" - depends on !CONFIG_FREERTOS_UNICORE + depends on !FREERTOS_UNICORE endchoice From 14f308b26f1425a915cd0f336c23321bdfa63a0e Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 10 May 2022 16:48:49 -0300 Subject: [PATCH 6/6] Fixing Core choice for OnReceive() Makes it alligned to changes in #6718 Also eliminates conflict with #6718 for merging --- Kconfig.projbuild | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index ad43d789937..e46615933aa 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -21,7 +21,8 @@ config AUTOSTART_ARDUINO choice ARDUINO_RUNNING_CORE bool "Core on which Arduino's setup() and loop() are running" - default ARDUINO_RUN_CORE1 + default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE + default ARDUINO_RUN_CORE1 if !FREERTOS_UNICORE help Select on which core Arduino's setup() and loop() functions run @@ -29,6 +30,7 @@ choice ARDUINO_RUNNING_CORE bool "CORE 0" config ARDUINO_RUN_CORE1 bool "CORE 1" + depends on !FREERTOS_UNICORE config ARDUINO_RUN_NO_AFFINITY bool "BOTH" depends on !FREERTOS_UNICORE @@ -49,7 +51,8 @@ config ARDUINO_LOOP_STACK_SIZE choice ARDUINO_EVENT_RUNNING_CORE bool "Core on which Arduino's event handler is running" - default ARDUINO_EVENT_RUN_CORE1 + default ARDUINO_EVENT_RUN_CORE0 if FREERTOS_UNICORE + default ARDUINO_EVENT_RUN_CORE1 if !FREERTOS_UNICORE help Select on which core Arduino's WiFi.onEvent() run @@ -57,6 +60,7 @@ choice ARDUINO_EVENT_RUNNING_CORE bool "CORE 0" config ARDUINO_EVENT_RUN_CORE1 bool "CORE 1" + depends on !FREERTOS_UNICORE config ARDUINO_EVENT_RUN_NO_AFFINITY bool "BOTH" depends on !FREERTOS_UNICORE @@ -71,7 +75,8 @@ config ARDUINO_EVENT_RUNNING_CORE choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE bool "Core on which Arduino's Serial Event task is running" - default ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY + default ARDUINO_SERIAL_EVENT_RUN_CORE0 if FREERTOS_UNICORE + default ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY if !FREERTOS_UNICORE help Select on which core Arduino's Serial Event task run @@ -79,6 +84,7 @@ choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE bool "CORE 0" config ARDUINO_SERIAL_EVENT_RUN_CORE1 bool "CORE 1" + depends on !FREERTOS_UNICORE config ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY bool "BOTH" depends on !FREERTOS_UNICORE @@ -103,15 +109,9 @@ config ARDUINO_SERIAL_EVENT_TASK_PRIORITY help Select at what priority you want the Serial Event task to run. -config ARDUINO_UDP_TASK_PRIORITY - int "Priority of the UDP task" - default 3 - help - Select at what priority you want the UDP task to run. - choice ARDUINO_UDP_RUNNING_CORE bool "Core on which Arduino's UDP is running" - default ARDUINO_UDP_RUN_CORE1 + default ARDUINO_UDP_RUN_CORE0 help Select on which core Arduino's UDP run @@ -119,6 +119,7 @@ choice ARDUINO_UDP_RUNNING_CORE bool "CORE 0" config ARDUINO_UDP_RUN_CORE1 bool "CORE 1" + depends on !FREERTOS_UNICORE config ARDUINO_UDP_RUN_NO_AFFINITY bool "BOTH" depends on !FREERTOS_UNICORE @@ -131,6 +132,12 @@ config ARDUINO_UDP_RUNNING_CORE default 1 if ARDUINO_UDP_RUN_CORE1 default -1 if ARDUINO_UDP_RUN_NO_AFFINITY +config ARDUINO_UDP_TASK_PRIORITY + int "Priority of the UDP task" + default 3 + help + Select at what priority you want the UDP task to run. + config ARDUINO_ISR_IRAM bool "Run interrupts in IRAM" default "n"