Skip to content

Commit 9613e0f

Browse files
committed
Increase background stack size to fix overflows
On platforms using both tickless and the low power ticker wrapper so much of the background stack is used that it overflows. To ensure the background thread's stack doesn't overflow increase this size by 256 bytes when tickless is enabled. Worst case usage on the NUCLEO_F476RG was recorded at 656 when tickless is turned on so this increased size should safely prevent overflows.
1 parent b18c819 commit 9613e0f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

rtos/TARGET_CORTEX/mbed_rtx_conf.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@
3939
#define OS_TIMER_THREAD_STACK_SIZE MBED_CONF_RTOS_TIMER_THREAD_STACK_SIZE
4040
#endif
4141

42+
// Increase the idle thread stack size when tickless is enabled
43+
#if defined(MBED_TICKLESS) && defined(LPTICKER_DELAY_TICKS) && (LPTICKER_DELAY_TICKS > 0)
44+
#define EXTRA_IDLE_STACK MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE_TICKLESS_EXTRA
45+
#else
46+
#define EXTRA_IDLE_STACK 0
47+
#endif
4248
#ifdef MBED_CONF_APP_IDLE_THREAD_STACK_SIZE
43-
#define OS_IDLE_THREAD_STACK_SIZE MBED_CONF_APP_IDLE_THREAD_STACK_SIZE
49+
#define OS_IDLE_THREAD_STACK_SIZE (MBED_CONF_APP_IDLE_THREAD_STACK_SIZE + EXTRA_IDLE_STACK)
4450
#else
45-
#define OS_IDLE_THREAD_STACK_SIZE MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE
51+
#define OS_IDLE_THREAD_STACK_SIZE (MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE + EXTRA_IDLE_STACK)
4652
#endif
4753

4854
#define OS_DYNAMIC_MEM_SIZE 0

rtos/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"thread-stack-size": {
1818
"help": "The default stack size of new threads",
1919
"value": 4096
20+
},
21+
"idle-thread-stack-size-tickless-extra": {
22+
"help": "Additional size to add to the idle thread when tickless is enabled and LPTICKER_DELAY_TICKS is used",
23+
"value": 256
2024
}
2125
},
2226
"macros": ["_RTE_"],

0 commit comments

Comments
 (0)