Skip to content

Commit b7cf1ab

Browse files
author
Cruz Monrreal
authored
Merge pull request #8039 from c1728p9/stack_size_framework
Add framework for configuring boot stack size
2 parents f529dc7 + 66cce67 commit b7cf1ab

File tree

6 files changed

+57
-13
lines changed

6 files changed

+57
-13
lines changed

rtos/mbed_lib.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,22 @@
1919
"value": 4096
2020
}
2121
},
22-
"macros": ["_RTE_"]
22+
"macros": ["_RTE_"],
23+
"target_overrides": {
24+
"*": {
25+
"target.boot-stack-size": "0x400"
26+
},
27+
"MCU_NRF51": {
28+
"target.boot-stack-size": "0x800"
29+
},
30+
"MCU_NRF52840": {
31+
"target.boot-stack-size": "0x800"
32+
},
33+
"MCU_NRF52832": {
34+
"target.boot-stack-size": "0x800"
35+
},
36+
"MCU_NRF51_UNIFIED": {
37+
"target.boot-stack-size": "0x800"
38+
}
39+
}
2340
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/TOOLCHAIN_ARM_STD/MK64FN1M0xxx12.sct

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
#define MBED_APP_SIZE 0x100000
6565
#endif
6666

67+
#if !defined(MBED_BOOT_STACK_SIZE)
68+
#define MBED_BOOT_STACK_SIZE 0x400
69+
#endif
70+
6771
#define m_interrupts_start MBED_APP_START
6872
#define m_interrupts_size 0x00000400
6973

@@ -86,7 +90,7 @@
8690
#if (defined(__stack_size__))
8791
#define Stack_Size __stack_size__
8892
#else
89-
#define Stack_Size 0x0400
93+
#define Stack_Size MBED_BOOT_STACK_SIZE
9094
#endif
9195

9296
#if (defined(__heap_size__))
@@ -122,4 +126,6 @@ LR_IROM1 m_interrupts_start m_text_start+m_text_size-m_interrupts_start { ; lo
122126
}
123127
RW_IRAM1 ImageLimit(RW_m_data_2) { ; Heap region growing up
124128
}
129+
ARM_LIB_STACK m_data_2_start+m_data_2_size EMPTY -Stack_Size { ; Stack region growing down
130+
}
125131
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/TOOLCHAIN_GCC_ARM/MK64FN1M0xxx12.ld

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ ENTRY(Reset_Handler)
5353

5454
__ram_vector_table__ = 1;
5555

56-
/* With the RTOS in use, this does not affect the main stack size. The size of
57-
* the stack where main runs is determined via the RTOS. */
58-
__stack_size__ = 0x400;
59-
60-
__heap_size__ = 0x6000;
61-
6256
#if !defined(MBED_APP_START)
6357
#define MBED_APP_START 0
6458
#endif
@@ -67,6 +61,16 @@ __heap_size__ = 0x6000;
6761
#define MBED_APP_SIZE 0x100000
6862
#endif
6963

64+
#if !defined(MBED_BOOT_STACK_SIZE)
65+
#define MBED_BOOT_STACK_SIZE 0x400
66+
#endif
67+
68+
/* With the RTOS in use, this does not affect the main stack size. The size of
69+
* the stack where main runs is determined via the RTOS. */
70+
__stack_size__ = MBED_BOOT_STACK_SIZE;
71+
72+
__heap_size__ = 0x6000;
73+
7074
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
7175
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
7276
M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0;
@@ -259,7 +263,7 @@ SECTIONS
259263
__end__ = .;
260264
PROVIDE(end = .);
261265
__HeapBase = .;
262-
. += HEAP_SIZE;
266+
. = ORIGIN(m_data_2) + LENGTH(m_data_2) - STACK_SIZE;
263267
__HeapLimit = .;
264268
__heap_limit = .; /* Add for _sbrk */
265269
} > m_data_2

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/TOOLCHAIN_IAR/MK64FN1M0xxx12.icf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
*/
5050
define symbol __ram_vector_table__ = 1;
5151

52-
/* Heap 1/4 of ram and stack 1/8 */
53-
define symbol __stack_size__=0x8000;
54-
define symbol __heap_size__=0x10000;
55-
5652
if (!isdefinedsymbol(MBED_APP_START)) {
5753
define symbol MBED_APP_START = 0;
5854
}
@@ -61,6 +57,13 @@ if (!isdefinedsymbol(MBED_APP_SIZE)) {
6157
define symbol MBED_APP_SIZE = 0x100000;
6258
}
6359

60+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
61+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
62+
}
63+
64+
define symbol __stack_size__=MBED_BOOT_STACK_SIZE;
65+
define symbol __heap_size__=0x10000;
66+
6467
define symbol __ram_vector_table_size__ = isdefinedsymbol(__ram_vector_table__) ? 0x00000400 : 0;
6568
define symbol __ram_vector_table_offset__ = isdefinedsymbol(__ram_vector_table__) ? 0x000003FF : 0;
6669

targets/targets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"network-default-interface-type": {
2121
"help": "Default network interface type. Typical options: null, ETHERNET, WIFI, CELLULAR, MESH",
2222
"value": null
23+
},
24+
"boot-stack-size": {
25+
"help": "Define the boot stack size in bytes. This value must be a multiple of 8",
26+
"value": "0x1000"
2327
}
2428
}
2529
},

tools/toolchains/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,15 @@ def add_regions(self):
742742
except ConfigException:
743743
pass
744744

745+
def add_linker_defines(self):
746+
stack_param = "target.boot-stack-size"
747+
params, _ = self.config_data
748+
749+
if stack_param in params:
750+
define_string = self.make_ld_define("MBED_BOOT_STACK_SIZE", int(params[stack_param].value, 0))
751+
self.ld.append(define_string)
752+
self.flags["ld"].append(define_string)
753+
745754
# Set the configuration data
746755
def set_config_data(self, config_data):
747756
self.config_data = config_data
@@ -753,6 +762,7 @@ def set_config_data(self, config_data):
753762
self.ld.append(define_string)
754763
self.flags["ld"].append(define_string)
755764
self.add_regions()
765+
self.add_linker_defines()
756766

757767
# Creates the configuration header if needed:
758768
# - if there is no configuration data, "mbed_config.h" is not create (or deleted if it exists).

0 commit comments

Comments
 (0)