1 year, 11 months ago.

Change main thread stack size

Hi all,

Running my program causes stack underflow. How can I change stack size of main thread? And, what is the upper limit of stack size? I am using MBED OS 5 with NUCLEO-F767ZI.

Thank you.

I can't answer this question, as it already has an accepted answer. But the prefered way of doing this (which works everywhere, also in online compiler), is to spin up a new thread with the required task size and letting the old thread die. E.g.

Thread app_thread(osPriorityNormal, 16 * 1024); // 16K stack

void run_app() {
   // normal application logic

int main() {
  // main thread dies now and frees 4K stack
posted by Jan Jongboom 27 Nov 2017

In Mbed OS 5.7 and up you can configure the main stack size in mbed_app.json. See https://os.mbed.com/docs/v5.7/reference/configuration.html

posted by Jan Jongboom 12 Mar 2018
Comment on this question

1 Answer

1 year, 11 months ago.

I'm using 5.4.2 offline in System Workbench. All I have to do is throw a #define in main file to increase stack size. I have no idea if this works in the online compiler or not.

#define OS_MAINSTKSIZE          256

It's in this file:


The 256 is the default for your F767ZI board.