From 09c0a39d2a97e12a6cd01c18e3a7bce8e62bd77f Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 13 May 2022 13:15:06 +0300 Subject: [PATCH 1/3] Update Kconfig to autoselect the proper running core (#6718) * Update Kconfig to autoselect the proper cunning core * Always run UDP on Core0 by default --- Kconfig.projbuild | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 0e9c628f138..85e66820691 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,8 +30,10 @@ 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 endchoice @@ -48,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 @@ -56,8 +60,10 @@ 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 endchoice @@ -69,7 +75,7 @@ config ARDUINO_EVENT_RUNNING_CORE 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 @@ -77,23 +83,25 @@ 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 endchoice -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_UDP_RUNNING_CORE int default 0 if ARDUINO_UDP_RUN_CORE0 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" @@ -356,3 +364,4 @@ config ARDUINO_SELECTIVE_Wire endmenu + From 5482315036c0ae67730dd88b469457341863bdfa Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 13 May 2022 13:19:47 +0300 Subject: [PATCH 2/3] Change SPI::transfer signature to match official Arduino API (#6734) --- libraries/SPI/src/SPI.cpp | 4 ++-- libraries/SPI/src/SPI.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/SPI/src/SPI.cpp b/libraries/SPI/src/SPI.cpp index c3f095e523a..23a35c0d357 100644 --- a/libraries/SPI/src/SPI.cpp +++ b/libraries/SPI/src/SPI.cpp @@ -265,9 +265,9 @@ void SPIClass::writeBytes(const uint8_t * data, uint32_t size) spiEndTransaction(_spi); } -void SPIClass::transfer(uint8_t * data, uint32_t size) +void SPIClass::transfer(void * data, uint32_t size) { - transferBytes(data, data, size); + transferBytes((const uint8_t *)data, (uint8_t *)data, size); } /** diff --git a/libraries/SPI/src/SPI.h b/libraries/SPI/src/SPI.h index 97bfcdab30b..7f07e5beb0d 100644 --- a/libraries/SPI/src/SPI.h +++ b/libraries/SPI/src/SPI.h @@ -73,7 +73,7 @@ class SPIClass void beginTransaction(SPISettings settings); void endTransaction(void); - void transfer(uint8_t * data, uint32_t size); + void transfer(void * data, uint32_t size); uint8_t transfer(uint8_t data); uint16_t transfer16(uint16_t data); uint32_t transfer32(uint32_t data); From ed33e157529082fd8942b7bd9561a9bea9cbe703 Mon Sep 17 00:00:00 2001 From: Gonzalo Brusco Date: Fri, 13 May 2022 05:57:13 -0500 Subject: [PATCH 3/3] Adjustable Serial Event Task Stack Size And Priority (#6685) * Adjustable Serial Event Task Stack Size And Priority * Added options to Kconfig * Added Core Affinity * Added CONFIG_FREERTOS_UNICORE * Removed _CONFIG from FREERTOS_UNICORE * Fixing Core choice for OnReceive() Makes it alligned to changes in #6718 Also eliminates conflict with #6718 for merging Co-authored-by: Rodrigo Garcia Co-authored-by: Me No Dev --- Kconfig.projbuild | 36 ++++++++++++++++++++++++++++++++++ cores/esp32/HardwareSerial.cpp | 14 ++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 85e66820691..40c594c072a 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -73,6 +73,42 @@ config ARDUINO_EVENT_RUNNING_CORE default 1 if ARDUINO_EVENT_RUN_CORE1 default -1 if ARDUINO_EVENT_RUN_NO_AFFINITY +choice ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE + bool "Core on which Arduino's Serial Event task is running" + 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 + + config ARDUINO_SERIAL_EVENT_RUN_CORE0 + 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 + +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 + 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. + choice ARDUINO_UDP_RUNNING_CORE bool "Core on which Arduino's UDP is running" default ARDUINO_UDP_RUN_CORE0 diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 323482a6bbf..acc1bd2c88b 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -9,6 +9,18 @@ #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 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 @@ -159,7 +171,7 @@ HardwareSerial::~HardwareSerial() void HardwareSerial::_createEventTask(void *args) { // Creating UART event Task - xTaskCreate(_uartEventTask, "uart_event_task", 2048, this, configMAX_PRIORITIES - 1, &_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); }