tim35ca
November 21, 2023, 7:16pm
1
I have a custom STM32L072 project using mbed-ce v6.17.0 bare-metal . I’m trying to adjust the main stack size from what appears to be hardcoded as 1024(0x400).
I have added the following to the mbed_app.json file under the “target_overrides”:
"main_stack_size": 2048,
"boot_stack_size": 2048,
The mbed-…-link_script.ld in the build directory has the following:
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
_estack = __StackTop;
__StackLimit = __StackTop - 0x400;
1 Like
JohnnyK
(Jan Kamidra)
November 21, 2023, 8:29pm
2
Hello,
this name seems to be old and wrong one, the current one is main-thread-stack-size
as you can see here .
The value 0x400 is just size of bootloader stack size. This part corresponds to this .
BR, Jan
tim35ca
November 21, 2023, 10:21pm
3
Thanks for the quick reply!
So I added
"main-thread-stack-size": 3072
to my mbed_app.json file. Here is the resulting and relevant section of the .elf.map file:
.heap 0x20002758 0x24a8
0x20002758 end = .
[!provide] PROVIDE (end = .)
(.heap )
0x20004c00 . = ((ORIGIN (RAM) + LENGTH (RAM)) - 0x400)
fill 0x20002758 0x24a8
0x20004c00 __HeapLimit = .
.stack_dummy
(.stack )
0x20005000 __StackTop = (ORIGIN (RAM) + LENGTH (RAM))
0x20005000 _estack = __StackTop
0x20004c00 __StackLimit = (__StackTop - 0x400)
0x20005000 PROVIDE (__stack = __StackTop)
0x00000001 ASSERT ((__StackLimit >= __HeapLimit), region RAM overflowed with stack)
I am not using a bootloader in this design so where should I be looking for the stack limit?
JohnnyK
(Jan Kamidra)
November 21, 2023, 10:48pm
4
The default value is 4096 so your new settings override in with new value to 3072.
To be honest I do not know but does not seem to be here. I also forgot you mentioned bare metal profile and this settings are stored in RTOS folder…
@MultipleMonomials any idea please?
BR, Jan
tim35ca
November 24, 2023, 11:55pm
5
So I tried a number of suggestions from the mbed docs regarding statck settings and then tried something obvious in the mbed_app.json file from the .ld file you pointed to above:
"target.boot-stack-size": "0x800",
As I would expect, the .ld file then showed:
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
_estack = __StackTop;
__StackLimit = __StackTop - 0x800;
PROVIDE(__stack = __StackTop);
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
So in the bare metal case, this seems to be the way to go.
One other thing related to this is the mbed stack stats feature does not seem to work. I have defined the following in mbed_app.json:
“macros”: [
“MBED_STACK_STATS_ENABLED=1”
],
And the following shows up in the build.…\mbed-os\mbed-target-config.h file:
#define MBED_STACK_STATS_ENABLED 1
But the stats all come back = 0
JohnnyK
(Jan Kamidra)
December 4, 2023, 5:49pm
6
Yes, this is working because there is the macro - MBED_CONF_TARGET_BOOT_STACK_SIZE
* values to stack symbols later */
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
_estack = __StackTop;
__StackLimit = __StackTop - MBED_CONF_TARGET_BOOT_STACK_SIZE;
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
BR, Jan