Tasks and cores in arduino-esp32
setup() and loop() run in an ordinary FreeRTOS task at priority 1. Most system tasks run far above it, and on dual-core chips the defaults keep them on core 0 while the sketch runs on core 1.
In short
- loopTask runs
setup()andloop()at priority 1 with an 8192-byte stack, on coreARDUINO_RUNNING_CORE(core 1 by default in the IDE on ESP32 and ESP32-S3).1 - FreeRTOS in ESP-IDF has 25 priority levels (0…24); Wi-Fi (23),
esp_timer(22), the event loop (20) and lwIP (18) all run aboveloop().2 - In ESP-IDF's defaults the Wi-Fi, Bluetooth controller,
esp_timerand event loop tasks are pinned to core 0; lwIP is not pinned.3 - Single-core chips run everything on core 0: ESP-IDF selects
FREERTOS_UNICOREfor them, and arduino-esp32 then defaults the loop to core 0.4
Tasks created by arduino-esp32
| Task | Runs | Priority | Core | Stack |
|---|---|---|---|---|
loopTask | setup(), loop(), serialEvent() | 1 | ARDUINO_RUNNING_CORE (IDE default: core 1) | 8192 bytes (Kconfig default)1 |
arduino_events | WiFi.onEvent() / Network.onEvent() callbacks | ESP_TASKD_EVENT_PRIO − 1 (19) | ARDUINO_EVENT_RUNNING_CORE (IDE default: core 1) | 4096 bytes5 |
uart_event_task | Serial.onReceive() / onReceiveError() callbacks | 24 (Kconfig default; configMAX_PRIORITIES − 1 without it) | not pinned (Kconfig default on dual-core chips) | 2048 bytes (Kconfig default)6 |
Stacks are in bytes (see below). Values marked "Kconfig default" are CONFIG_ARDUINO_* options of arduino-esp32's Kconfig.projbuild; the core uses the CONFIG_ value when the prebuilt libraries' sdkconfig defines it, and none of the lib-builder 6671d0b configs/defconfig.* files sets these options. arduino_events is created by NetworkEvents::initNetworkEvents(), which also creates the default event loop; uart_event_task only when onReceive() or onReceiveError() is set.
ESP-IDF system tasks
Priorities and cores are the ESP-IDF v5.5.5 defaults. The prebuilt libraries used by arduino-esp32 set their own sdkconfig, which is not checked here.
| Task | Runs | Priority | Core | Stack |
|---|---|---|---|---|
main | app_main(): Arduino creates loopTask here and returns | 1 | 0 | —3 |
Wi-Fi driver | Wi-Fi | 23 | 0 (ESP_WIFI_TASK_CORE_ID) | —3 |
BT controller | Bluetooth controller and HCI | 23 (ESP_TASK_BT_CONTROLLER_PRIO) | 0 | —3 |
esp_timer | esp_timer callbacks | 22 (ESP_TASK_TIMER_PRIO) | 0 | —3 |
NimBLE host | BLE host (NimBLE) | 21 | 0 | —3 |
sys_evt | default event loop | 20 (ESP_TASKD_EVENT_PRIO) | 0 | —3 |
tcpip | lwIP TCP/IP stack | 18 (LWIP_TCPIP_TASK_PRIO) | not pinned (LWIP_TCPIP_TASK_AFFINITY) | —3 |
Tmr Svc | FreeRTOS software timers | 1 | 0 | —3 |
IDLE0 / IDLE1 | idle task, one per core | 0 | each core | —7 |
Core numbers apply to dual-core chips; on single-core chips there is only core 0.
Single-core and dual-core chips
| Chip | CPU cores | FREERTOS_UNICORE | loopTask core |
|---|---|---|---|
| ESP32 | 28 | no | 1 (IDE menu "Arduino Runs On")9 |
| ESP32-S2 | 110 | yes4 | 011 |
| ESP32-S3 | 212 | no | 1 (IDE menu "Arduino Runs On")9 |
| ESP32-C2 | 113 | yes4 | 011 |
| ESP32-C3 | 114 | yes4 | 011 |
| ESP32-C5 | 115 | yes4 | 011 |
| ESP32-C6 | 116 | yes4 | 011 |
| ESP32-C61 | 117 | yes4 | 011 |
| ESP32-H2 | 118 | yes4 | 011 |
| ESP32-P4 | 219 | no | 1 (Kconfig default; no IDE menu)11 |
loopTask core: the IDE menu default for the generic Dev Module where boards.txt has one, otherwise the Kconfig.projbuild default.
Changing the loop stack size
SET_LOOP_TASK_STACK_SIZE()
getArduinoLoopTaskStackSize() is a weak function returning 8192; the macro SET_LOOP_TASK_STACK_SIZE(sz) in the sketch replaces it.1
Units
In ESP-IDF FreeRTOS stack sizes are given in bytes, not words, and uxTaskGetStackHighWaterMark() also returns bytes.7
SET_LOOP_TASK_STACK_SIZE(16 * 1024); // loopTask gets 16 KB instead of 8 KB
void setup() {
Serial.begin(115200);
Serial.printf("loop on core %d, priority %u\n", xPortGetCoreID(), uxTaskPriorityGet(NULL));
}
void loop() {
Serial.printf("free stack: %u bytes\n", uxTaskGetStackHighWaterMark(NULL));
delay(1000);
}Pitfalls
The loop task is not on the task watchdog
loopTaskWDTEnabled starts false; only enableLoopWDT() adds loopTask to the task watchdog. ESP-IDF's own defaults watch the idle task of each CPU with a 5 s timeout, but the arduino-esp32 libraries are built with the idle check of the loop's core turned off (CPU1 on ESP32 and ESP32-S3, CPU0 on single-core chips such as ESP32-S2 and ESP32-C3). So by default a loop() that never blocks does not trip the task watchdog through the idle task of its core.1
Single-core yield in loopTask
With FREERTOS_UNICORE, loopTask calls vTaskDelay(5) once more than 2000 ms have passed since the last such delay, so lower-priority tasks get some time even if loop() never blocks.1
onReceive() callbacks run at priority 24
uart_event_task is created at configMAX_PRIORITIES − 1, above the Wi-Fi task; a long callback delays every lower-priority task on the core it runs on.20
serialEvent() is not a task
serialEvent() is called from loopTask after each loop(), so it only runs when loop() returns.1
See also
- Two cores, one counter: why counter++ loses updates on ESP32
- ESP32 chip families: compare and choose
- CPU frequency: allowed setCpuFrequencyMhz() values
- Deep-sleep wakeup sources per chip
Sources
Each number links here; open “What it confirms” for the exact quotes. Checked 2026-11-28.
- arduino-esp32 3.3.12: cores/esp32/main.cpp primary
What it confirms (6)
- Tasks and cores in arduino-esp32: in short “xTaskCreateUniversal(loopTask, "loopTask", getArduinoLoopTaskStackSize(), NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE); … #define ARDUINO_LOOP_STACK_SIZE 8192 … esp32.menu.LoopCore.1=Core 1”
- Tasks and cores in arduino-esp32: loopTask “xTaskCreateUniversal(loopTask, "loopTask", getArduinoLoopTaskStackSize(), NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE); … #define ARDUINO_LOOP_STACK_SIZE 8192 … serialEventRun(); … esp32s3.menu.LoopCore.1=Core 1 … esp32s3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 … #define ARDUINO_LOOP_STACK_SIZE CONFIG_ARDUINO_LOOP_STACK_SIZE … config ARDUINO_LOOP_STACK_SIZE int "Loop thread stack size" default 8192”
- Tasks and cores in arduino-esp32: SET_LOOP_TASK_STACK_SIZE() “__attribute__((weak)) size_t getArduinoLoopTaskStackSize(void) { … #define SET_LOOP_TASK_STACK_SIZE(sz) \ … size_t getArduinoLoopTaskStackSize() { \”
- Tasks and cores in arduino-esp32: pitfall: The loop task is not on the task watchdog “loopTaskWDTEnabled = false; … if (esp_task_wdt_add(loopTaskHandle) != ESP_OK) { … config ESP_TASK_WDT_TIMEOUT_S int "Task Watchdog timeout period (seconds)" depends on ESP_TASK_WDT_INIT range 1 60 default 5 … The TWDT primarily watches the Idle Tasks of each CPU … config ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 bool "Watch CPU1 Idle Task" depends on ESP_TASK_WDT_INIT && !FREERTOS_UNICORE default y … # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set … # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set”
- Tasks and cores in arduino-esp32: pitfall: Single-core yield in loopTask “#if CONFIG_FREERTOS_UNICORE … if ((now - lastYield) > 2000) { … vTaskDelay(5);”
- Tasks and cores in arduino-esp32: pitfall: serialEvent() is not a task “loop(); … if (serialEventRun) { … serialEventRun();”
- ESP-IDF v5.5.5: components/freertos/config/include/freertos/FreeRTOSConfig.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: in short “#define configMAX_PRIORITIES ( 25 ) … Wi-Fi Driver task has high priority (23) … has high priority (22, ESP_TASK_TIMER_PRIO) … has high priority (20, ESP_TASK_EVENT_PRIO) … lwIP TCP/IP task has high priority (18, ESP_TASK_TCPIP_PRIO)”
- ESP-IDF v5.5.5 docs (ESP32-S3): Maximizing Execution Speed primary
What it confirms (9)
- Tasks and cores in arduino-esp32: in short “Wi-Fi Driver task has high priority (23) and is pinned to Core 0 by default (configurable). … This task is pinned to Core 0. … is not pinned to any core (configurable).”
- Tasks and cores in arduino-esp32: main “Running the Main Task that executes app_main function has minimum priority (1). This task is pinned to Core 0 by default (configurable). … If app_main() returns then this task is deleted. … extern "C" void app_main() {”
- Tasks and cores in arduino-esp32: Wi-Fi driver “Wi-Fi Driver task has high priority (23) and is pinned to Core 0 by default (configurable). … choice ESP_WIFI_TASK_CORE_ID depends on !FREERTOS_UNICORE prompt "WiFi Task Core ID" default ESP_WIFI_TASK_PINNED_TO_CORE_0”
- Tasks and cores in arduino-esp32: BT controller “Controller & HCI task has high priority (23, ESP_TASK_BT_CONTROLLER_PRIO) and is pinned to Core 0 by default (configurable). … #define ESP_TASK_BT_CONTROLLER_PRIO (ESP_TASK_PRIO_MAX - 2)”
- Tasks and cores in arduino-esp32: esp_timer “ESP Timer (High Resolution Timer) system task to manage high precision timer events and execute callbacks has high priority (22, ESP_TASK_TIMER_PRIO). This task is pinned to Core 0. … #define ESP_TASK_TIMER_PRIO (ESP_TASK_PRIO_MAX - 3)”
- Tasks and cores in arduino-esp32: NimBLE host “NimBLE-based Host APIs task has high priority (21) and is pinned to Core 0 by default (configurable).”
- Tasks and cores in arduino-esp32: sys_evt “Event Loop Library system task to manage the default system event loop and execute callbacks has high priority (20, ESP_TASK_EVENT_PRIO) and it is pinned to Core 0. … esp_err_t err = esp_event_loop_create_default();”
- Tasks and cores in arduino-esp32: tcpip “lwIP TCP/IP task has high priority (18, ESP_TASK_TCPIP_PRIO) and is not pinned to any core (configurable). … config LWIP_TCPIP_TASK_PRIO int "LWIP TCP/IP Task Priority" default 18 … default LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY”
- Tasks and cores in arduino-esp32: Tmr Svc “FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, configurable). This task is pinned to Core 0. … config FREERTOS_TIMER_TASK_PRIORITY int "configTIMER_TASK_PRIORITY" range 1 25 default 1”
- ESP-IDF v5.5.5: Kconfig primary
What it confirms (8)
- Tasks and cores in arduino-esp32: in short “select FREERTOS_UNICORE … default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-S2 / FREERTOS_UNICORE “config IDF_TARGET_ESP32S2 bool default "y" if IDF_TARGET="esp32s2" select FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C2 / FREERTOS_UNICORE “config IDF_TARGET_ESP32C2 bool default "y" if IDF_TARGET="esp32c2" select FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C3 / FREERTOS_UNICORE “config IDF_TARGET_ESP32C3 bool default "y" if IDF_TARGET="esp32c3" select FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C5 / FREERTOS_UNICORE “config IDF_TARGET_ESP32C5 bool default "y" if IDF_TARGET="esp32c5" select FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C6 / FREERTOS_UNICORE “config IDF_TARGET_ESP32C6 bool default "y" if IDF_TARGET="esp32c6" select FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C61 / FREERTOS_UNICORE “config IDF_TARGET_ESP32C61 bool default "y" if IDF_TARGET="esp32c61" select FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-H2 / FREERTOS_UNICORE “config IDF_TARGET_ESP32H2 bool default "y" if IDF_TARGET="esp32h2" select FREERTOS_UNICORE”
- arduino-esp32 3.3.12: libraries/Network/src/NetworkEvents.cpp primary
What it confirms (1)
- Tasks and cores in arduino-esp32: arduino_events “"arduino_events", … this, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE … #define ARDUINO_NETWORK_EVENT_TASK_STACK_SIZE 4096 … #define ESP_TASKD_EVENT_PRIO (ESP_TASK_PRIO_MAX - 5) … #define ESP_TASK_PRIO_MAX (configMAX_PRIORITIES) … #define configMAX_PRIORITIES ( 25 ) … esp32s3.menu.EventsCore.1=Core 1”
- arduino-esp32 3.3.12: cores/esp32/HardwareSerial.cpp primary
What it confirms (1)
- Tasks and cores in arduino-esp32: uart_event_task “_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask, … #define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048 … #define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES - 1) … #define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1 … uart->_onReceiveCB(); … return xTaskCreate(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask); … #define ARDUINO_SERIAL_EVENT_TASK_PRIORITY CONFIG_ARDUINO_SERIAL_EVENT_TASK_PRIORITY … config ARDUINO_SERIAL_EVENT_TASK_PRIORITY int "Priority of the Serial Event task" default 24 … default ARDUINO_SERIAL_EVENT_RUN_NO_AFFINITY if !FREERTOS_UNICORE … config ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE int "Serial Event task stack size" default 2048”
- ESP-IDF v5.5.5 docs (ESP32-S3): freertos_idf primary
What it confirms (2)
- Tasks and cores in arduino-esp32: IDLE0 / IDLE1 “Vanilla FreeRTOS will implicitly create an idle task of priority 0 when the scheduler is started. … In IDF FreeRTOS, a separate pinned idle task is created for each core.”
- Tasks and cores in arduino-esp32: Units “whereas in IDF FreeRTOS, the task stack sizes are specified in bytes. … the minimum free stack space there has been in bytes (as opposed to words in the standard FreeRTOS documentation)”
- ESP-IDF v5.5.5: components/soc/esp32/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32 / CPU cores “#define SOC_CPU_CORES_NUM 2”
- arduino-esp32 3.3.12: boards.txt primary
What it confirms (2)
- Tasks and cores in arduino-esp32: ESP32 / loopTask core “esp32.menu.LoopCore.1=Core 1 … esp32.menu.LoopCore.0=Core 0”
- Tasks and cores in arduino-esp32: ESP32-S3 / loopTask core “esp32s3.menu.LoopCore.1=Core 1 … esp32s3.menu.LoopCore.0=Core 0”
- ESP-IDF v5.5.5: components/soc/esp32s2/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-S2 / CPU cores “#define SOC_CPU_CORES_NUM (1U)”
- arduino-esp32 3.3.12: Kconfig.projbuild primary
What it confirms (8)
- Tasks and cores in arduino-esp32: ESP32-S2 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C2 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C3 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C5 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C6 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-C61 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-H2 / loopTask core “default ARDUINO_RUN_CORE0 if FREERTOS_UNICORE”
- Tasks and cores in arduino-esp32: ESP32-P4 / loopTask core “default ARDUINO_RUN_CORE1 if !FREERTOS_UNICORE”
- ESP-IDF v5.5.5: components/soc/esp32s3/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-S3 / CPU cores “SOC_CPU_CORES_NUM 2”
- ESP-IDF v5.5.5: components/soc/esp32c2/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-C2 / CPU cores “SOC_CPU_CORES_NUM (1U)”
- ESP-IDF v5.5.5: components/soc/esp32c3/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-C3 / CPU cores “#define SOC_CPU_CORES_NUM (1U)”
- ESP-IDF v5.5.5: components/soc/esp32c5/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-C5 / CPU cores “#define SOC_CPU_CORES_NUM (1U)”
- ESP-IDF v5.5.5: components/soc/esp32c6/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-C6 / CPU cores “#define SOC_CPU_CORES_NUM (1U)”
- ESP-IDF v5.5.5: components/soc/esp32c61/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-C61 / CPU cores “#define SOC_CPU_CORES_NUM (1U)”
- ESP-IDF v5.5.5: components/soc/esp32h2/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-H2 / CPU cores “#define SOC_CPU_CORES_NUM (1U)”
- ESP-IDF v5.5.5: components/soc/esp32p4/include/soc/soc_caps.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: ESP32-P4 / CPU cores “#define SOC_CPU_CORES_NUM (2U)”
- arduino-esp32 3.3.12: cores/esp32/HardwareSerial.h primary
What it confirms (1)
- Tasks and cores in arduino-esp32: pitfall: onReceive() callbacks run at priority 24 “#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES - 1) … Wi-Fi Driver task has high priority (23)”