embedded
runtime_error
ai_generated
true
FreeRTOS: Stack overflow detected in task 'MainTask' (high water mark: 0)
ID: embedded/stack-overflow-detected
85%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 32 | active | — | — | — |
Root Cause
RTOS task stack overflowed. Stack too small for call depth, large local arrays, or recursive calls.
genericWorkarounds
-
92% success Check high water mark and increase offending task stack
UBaseType_t hwm = uxTaskGetStackHighWaterMark(NULL); // words remaining. Increase stack by deficit + margin.
Sources: https://openocd.org/doc/html/
-
88% success Move large local arrays to static or heap allocation
static uint8_t buf[1024]; // instead of stack-allocated. Or use pvPortMalloc().
-
85% success Enable configCHECK_FOR_STACK_OVERFLOW=2 for early detection
#define configCHECK_FOR_STACK_OVERFLOW 2 // checks watermark on every context switch
Dead Ends
Common approaches that don't work:
-
Double all task stack sizes blindly
72% fail
Wastes precious SRAM. Identify the offending task and size its stack based on actual usage.
-
Disable stack overflow checking to hide the error
90% fail
Stack corruption continues silently, corrupting adjacent task stacks or heap, causing random crashes.