Skip to content

Commit 4e7e859

Browse files
committed
freertos: ensure the interrupt stack is aligned
CONFIG_FREERTOS_ISR_STACKSIZE was set to 2100 when ELF core dump was enabled, which resulted in a non-16-byte-aligned interrupt stack offset. This triggered "is SP corrupted" check in the backtrace, terminating the backtrace early. Fix the default value, and make sure that the stack is always aligned, regardless of the value of CONFIG_FREERTOS_ISR_STACKSIZE.
1 parent 481409e commit 4e7e859

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

components/freertos/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ menu "FreeRTOS"
174174

175175
config FREERTOS_ISR_STACKSIZE
176176
int "ISR stack size"
177-
range 2100 32768 if ESP32_COREDUMP_DATA_FORMAT_ELF
178-
default 2100 if ESP32_COREDUMP_DATA_FORMAT_ELF
177+
range 2096 32768 if ESP32_COREDUMP_DATA_FORMAT_ELF
178+
default 2096 if ESP32_COREDUMP_DATA_FORMAT_ELF
179179
range 1536 32768
180180
default 1536
181181
help

components/freertos/xtensa/include/freertos/FreeRTOSConfig.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,16 @@ int xt_clock_freq(void) __attribute__((deprecated));
196196
#define configIDLE_TASK_STACK_SIZE CONFIG_FREERTOS_IDLE_TASK_STACKSIZE
197197
#endif
198198

199-
/* The Xtensa port uses a separate interrupt stack. Adjust the stack size */
200-
/* to suit the needs of your specific application. */
199+
/* Stack alignment, architecture specifc. Must be a power of two. */
200+
#define configSTACK_ALIGNMENT 16
201+
202+
/* The Xtensa port uses a separate interrupt stack. Adjust the stack size
203+
* to suit the needs of your specific application.
204+
* Size needs to be aligned to the stack increment, since the location of
205+
* the stack for the 2nd CPU will be calculated using configISR_STACK_SIZE.
206+
*/
201207
#ifndef configISR_STACK_SIZE
202-
#define configISR_STACK_SIZE CONFIG_FREERTOS_ISR_STACKSIZE
208+
#define configISR_STACK_SIZE ((CONFIG_FREERTOS_ISR_STACKSIZE + configSTACK_ALIGNMENT - 1) & (~(configSTACK_ALIGNMENT - 1)))
203209
#endif
204210

205211
/* Minimal heap size to make sure examples can run on memory limited

0 commit comments

Comments
 (0)