section `.stack_dummy' will not fit in region `RAM'


I am using a S3A3 ucontroller which has 96KB RAM.

When I compile my code, the console windows shows that I am using 90256 bytes of RAM.

Then, when I add a new function, which is very simple, it stops compiling and shows that error:

"section `.stack_dummy' will not fit in region `RAM'

region `RAM' overflowed by 552 bytes"

I was expecting to have almost 6KB of free RAM yet.

What I am missing?

  • Hi Mad River,

    You should look carefully at you map file for your project. How do you know you are using 90256 bytes of ram?
    Does this include the Heap & Stack? The main heap & stack default to 4k each. This can be changed on the BSP properties tab in the Synergy Configuration window.

  • Hello Mad River,

    As Gary suggested, you should investigate the map file (it should be produced even if linking fails at the end).
    In the build console output, RAM usage is bss + data, not bss alone. If you're not using floats with printf or sscanf in general, you can disable heap (i.e. set its size to 0) on the BSP tab. Main stack size on the BSP tab should be sufficient when decreased to around 0x200-0x400, since it's hardly used after ThreadX kernel is entered.

  • In reply to Renesas Karol:


    Thank you both for the fast reply.

    I don't experience with map files, so I will put here the math I am using and hope you can tell me if it is right.

    That is the map file when it compiles:

    The total RAM usage is given by ".data + .bss + .heap + .stack_dummy". Is it correct?

    In this case, total RAM usage = 7549 + 66381 + 8192 + 15360 = 97482 bytes.

    As I have 96K (98304 bytes) it fits the available RAM.

    When it is not compiling, that is the map file:

    The same calc gives a total RAM used of = 8577 + 66381 + 8192 + 15360 = 98510 bytes.

    As I have 98304 bytes available, I won't fit the RAM.

    According to this math, I am using 206 bytes more than the available. The compiler console says that I am using 552 bytes more. So I am probably missing something in the math. What is that?


    Now, I need some tips to reduce the RAM usage.

    My threads stack sizes are a lot bigger than it should be. I took a look at the RTOS Resources window to know what is the maximum ram used by each thread. I tried to reduce these stack sizes, but my program stops working when I do that. I will give a deeper look on that.

    If you're not using floats with printf or sscanf in general, you can disable heap (i.e. set its size to 0) on the BSP tab.

    Regarding this, I am using sprintf to manipulate strings. Should this be a problem?

  • In reply to Mad River:

    The DTC vector table is placed in RAM, and has it's own section .ssp_dtc_vector_table, that is 192 bytes long that you have not taken into account. Also, the .noinit section will also take space in the RAM, this section is 56 bytes long
  • In reply to Jeremy:

    Also, the sections for the hardware locks .hwlock* are placed into RAM, the size of this is not shown in your post.
  • In reply to Jeremy:

    Hi Jeremy,

    Thank you for your answer.

    Well, I succesfully reduced my threads stacks sizes and it is still working.

    But I need to free a lot more RAM, since that are some features that aren't implemented yet.

    I can see that the touch thread have 3072 bytes, but is only using 364. Similiar issue with the ux_storage_thread. Is there a way to reduce these stack sizes?

    Regarding the Heap and Main Stack sizes, I am using now for each 0x1000. Can I reduce it a little more? I am using sprintf().

  • In reply to Mad River:

    Hi Mad River,

    Unfortunately the stack size for the touch thread cannot be changed. The size of ux_storage_thread's stack can be changed by defining UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE macro or USBX global UX_THREAD_STACK_SIZE macro. Please remember to add the USBX Source and the ThreadX Source components and rebuild the project.

    I'm not sure if the heap size can be reduce when using sprintf(), but you may try to reduce the main stack size to 0x0800 or lower.

  • In reply to Mad River:

    Hi Mad River,

    On GCC, sprintf() doesn't use any heap as long as you're not using floats (which are by default disabled anyway). Main stack is only used for interrupts (some parts of the scheduler also run in ISR).

  • In reply to Renesas Karol:

    Thank you both for your answers!