From 5e48ecedb76238ac89acae3f35608a3854a3cb92 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Thu, 25 Oct 2018 15:01:59 -0500 Subject: [PATCH] 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. --- rtos/TARGET_CORTEX/mbed_rtx_conf.h | 12 +++++++++--- rtos/mbed_lib.json | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rtos/TARGET_CORTEX/mbed_rtx_conf.h b/rtos/TARGET_CORTEX/mbed_rtx_conf.h index f0b2fc3984..8554098e24 100644 --- a/rtos/TARGET_CORTEX/mbed_rtx_conf.h +++ b/rtos/TARGET_CORTEX/mbed_rtx_conf.h @@ -39,10 +39,16 @@ #define OS_TIMER_THREAD_STACK_SIZE MBED_CONF_RTOS_TIMER_THREAD_STACK_SIZE #endif -#ifdef MBED_CONF_APP_IDLE_THREAD_STACK_SIZE -#define OS_IDLE_THREAD_STACK_SIZE MBED_CONF_APP_IDLE_THREAD_STACK_SIZE +// Increase the idle thread stack size when tickless is enabled +#if defined(MBED_TICKLESS) && defined(LPTICKER_DELAY_TICKS) && (LPTICKER_DELAY_TICKS > 0) +#define EXTRA_IDLE_STACK MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE_TICKLESS_EXTRA #else -#define OS_IDLE_THREAD_STACK_SIZE MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE +#define EXTRA_IDLE_STACK 0 +#endif +#ifdef MBED_CONF_APP_IDLE_THREAD_STACK_SIZE +#define OS_IDLE_THREAD_STACK_SIZE (MBED_CONF_APP_IDLE_THREAD_STACK_SIZE + EXTRA_IDLE_STACK) +#else +#define OS_IDLE_THREAD_STACK_SIZE (MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE + EXTRA_IDLE_STACK) #endif #define OS_DYNAMIC_MEM_SIZE 0 diff --git a/rtos/mbed_lib.json b/rtos/mbed_lib.json index 7714cdd743..4f75ee88df 100644 --- a/rtos/mbed_lib.json +++ b/rtos/mbed_lib.json @@ -17,6 +17,10 @@ "thread-stack-size": { "help": "The default stack size of new threads", "value": 4096 + }, + "idle-thread-stack-size-tickless-extra": { + "help": "Additional size to add to the idle thread when tickless is enabled and LPTICKER_DELAY_TICKS is used", + "value": 256 } }, "macros": ["_RTE_"]