4. 2.3 Stack size et watchdog
Stack overflow : la cause n°1 de crash chez les débutants FreeRTOS. Chaque tâche a sa propre pile allouée au démarrage. Si elle déborde, le watchdog ou le stack overflow hook se déclenche.
Activer la détection dans idf.py menuconfig :
Component config → FreeRTOS → Check for stack overflow → Method 2 (pattern)
Implémenter le hook de détection :
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName) {
ESP_LOGE("WATCHDOG", "Stack overflow in task: %s", pcTaskName);
esp_restart();
}
Dimensionner la pile :
| Usage | Stack recommandée |
|---|---|
| Tâche simple (pas de printf) | 2048 bytes |
| Tâche avec ESP_LOGI | 4096 bytes |
| Tâche avec JSON/snprintf | 8192 bytes |
| Tâche WiFi/HTTP | 8192–16384 bytes |
Mesurer avec uxTaskGetStackHighWaterMark(handle) (voir Module 4).