Skip to content

Adjustable Serial Event Task Stack Size And Priority #6685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 13, 2022
36 changes: 36 additions & 0 deletions Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option should depend on wether the chip has more than one core. Example implementation: https://github.com/espressif/esp-idf/blob/master/components/lwip/Kconfig#L675

Copy link
Contributor Author

@gonzabrusco gonzabrusco May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @me-no-dev , I'm a bit confused about this suggestion. In the other config entries (about running cores) there's no dependency on this define, should this be added to every entry aswell?

Also, I did a search about that specific define, but I've found CONFIG_FREERTOS_UNICORE and not FREERTOS_UNICORE, is that a bug in the line you linked to me?

I guess I could answer myself some of these questions, but I don't really know how to test this. I don't know what's the procedure to use this kconfig file. Could you point me to a guide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead anyway and pushed some changes. Let me know if I did it right! Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_ prefix is added to KConfig Options in its created header file automaticaly.
So Kconfig Menu option FREERTOS_UNICORE will be seen as a #define CONFIG_FREERTOS_UNICORE in the source code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may need to review it in the whole Kconfig.projectbuild.

I also got the same doubt as @gonzabrusco ...
Shall we include this dependency for all not valid options when there is just one Core (S2/C3)?
Should the default option go to Core0 when there is just one Core?

Copy link
Contributor Author

@gonzabrusco gonzabrusco May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we use xTaskCreateUniversal it does not matter the default option.

BaseType_t xTaskCreateUniversal( TaskFunction_t pxTaskCode,

By the way, thanks for the explanation on KConfig options. I removed the CONFIG_ prefix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True that xTaskCreateUniversal will take care regardless of how many cores, but this is a safe-net inside the function itself. It still makes sense to hide options that are invalid for the current target in ESP-IDF. This is how it is done for all IDF components. Arduino is no different :)

I think we may need to review it in the whole Kconfig.projectbuild.

Probably. It has not really been touched since ESP32, which has 2 cores always :D At least what we support for it.

Copy link
Contributor Author

@gonzabrusco gonzabrusco May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on vacation now, so feel free to change whatever you want to move this forward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not in a hurry, so no worries :) Have fun at your vacation

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
Expand Down
14 changes: 13 additions & 1 deletion cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down