Skip to content

Commit 535ee8b

Browse files
bulislaw0xc0170
authored andcommitted
Make stack sizes configurable by the app
Application can overwrite stack sizes by defining main-stack-size and thread-stack-size in mbed_app.json
1 parent abcae6f commit 535ee8b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

rtos/mbed_boot.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ WEAK void mbed_main(void);
178178
void pre_main (void);
179179

180180
osThreadAttr_t _main_thread_attr;
181-
/* The main stack size is hardcoded on purpose, so it's less tempting to change it per platform. As usually it's not
182-
* the correct solution to the problem and it makes mbed OS behave differently on different targets.
183-
*/
184-
MBED_ALIGN(8) char _main_stack[4096];
181+
182+
/** The main thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */
183+
#ifndef MBED_CONF_APP_MAIN_STACK_SIZE
184+
#define MBED_CONF_APP_MAIN_STACK_SIZE 4096
185+
#endif
186+
MBED_ALIGN(8) char _main_stack[MBED_CONF_APP_MAIN_STACK_SIZE];
185187
mbed_rtos_storage_thread_t _main_obj;
186188

187189
osMutexId_t singleton_mutex_id;

rtos/rtx2/mbed_rtx_conf.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424

2525
#include "mbed_rtx.h"
2626

27-
#ifndef OS_STACK_SIZE
28-
#ifndef MBED_SMALL_TARGET
29-
#define OS_STACK_SIZE 4096
30-
#else
31-
#define OS_STACK_SIZE 2048
32-
#endif
27+
/** The thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */
28+
#ifndef MBED_CONF_APP_THREAD_STACK_SIZE
29+
#define MBED_CONF_APP_THREAD_STACK_SIZE 4096
3330
#endif
3431

32+
#define OS_STACK_SIZE MBED_CONF_APP_THREAD_STACK_SIZE
33+
3534
#define OS_TIMER_THREAD_STACK_SIZE 768
3635
#define OS_IDLE_THREAD_STACK_SIZE 256
3736

0 commit comments

Comments
 (0)