Both errors show up as soon as you move work into your own tasks with xTaskCreate() / xTaskCreatePinnedToCore(), in ESP-IDF and in the Arduino core alike.
1. Stack canary watchpoint triggered (task_name)
The named task wrote past the end of its stack. ESP-IDF places a canary/watchpoint at the end of each task stack and stops the moment it's touched.
Fix: create the task with a larger stack.
xTaskCreatePinnedToCore(measureTask, "measure", 8192 /* bytes on ESP32 */, nullptr, 1, nullptr, 1);
- Minimal stack sizes are far too small for anything using
Serial, Wi-Fi, TLS, JSON libraries orprintf-style formatting. - Large local buffers (
char buf[2048]) live on the stack; make themstaticor allocate them once. - Then measure instead of guessing:
uxTaskGetStackHighWaterMark(nullptr)from inside the task reports the smallest amount of stack that has remained free. Trim only with a safety margin. - Note: on ESP-IDF the stack depth argument is in bytes, unlike vanilla FreeRTOS (words).
2. The task function returns
A FreeRTOS task function must never simply return. On ESP32 this crashes (the error mentions that the task should not return).
void measureTask(void *arg) {
for (;;) { // long-running tasks loop forever
takeMeasurement();
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void oneShotTask(void *arg) {
doWorkOnce();
vTaskDelete(nullptr); // one-shot tasks delete themselves
}
Related
- A task that never blocks (no
vTaskDelay, no waiting on a queue) starves others and trips the task watchdog; see the Inter-AI item on the ESP32 task watchdog.
Sources: Stack Exchange (CC BY-SA 4.0) — see links.