Arm Mbed OS support forum

How to change stack size

Board FRDM-K64F
mbed OS 5.13.4

A stack overflow has occurred.
I want to increase the stack size, where is it defined?

Error Message: CMSIS-RTOS error: Stack overflow
// Current Thread: main Id: 0x20002CD0 Entry: 0x31895
StackSize: 0x1000 StackMem: 0x1FFFA850 SP: 0x2002FF58

I’ve already tried to change the following macro definition, but the error message hasn’t changed and the stack size remained 0x1000.


Thank you.


stands inside the file mbed_config.h

// Automatically generated configuration file.
// DO NOT EDIT, content will be overwritten.

Because these macros are auto generated before compiling from content of many .json files across the MbedOS. So you probably need change it via mbed_app.json file.

This version of Mbed OS is too much old so documentation is not available but it will be same or similar -
The configuration system - Program setup | Mbed OS 6 Documentation

BR, Jan


I tried your advice, and it worked!
I changed rtos\mbed_lib.json file.

"config": {

    "present": 1,

     "main-thread-stack-size": {

        "help": "The size of the main thread's stack",

        "value": 8192


Thank you!

Hello again,

I’m glad you found what you needed.

However, small correction.
This way is possible but when you update or downgrade MbedOS you will lost this setting and will must be set again every time, when you will manipulate with MbedOS version.
Therefore, it is better to create mbed_app.json in the project folder and place the same content in this file. That will overide original config from the rtos\mbed_lib.json file.

    "config": {
        "main-stack-size": {
            "value": 8192

BR, Jan


Again, thanks for the comment!
I’ll follow your advice.
(I already checked your suggestion worked)

Thank you.

1 Like