Skip to content

Commit 1576fb0

Browse files
author
Deepika
committed
Add support for split heap in ST devices
1 parent 1a52587 commit 1576fb0

File tree

5 files changed

+186
-101
lines changed

5 files changed

+186
-101
lines changed

targets/TARGET_STM/TARGET_STM32L4/TARGET_MTS_DRAGONFLY_L471QG/device/TOOLCHAIN_GCC_ARM/STM32L471XX.ld

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ STACK_SIZE = MBED_BOOT_STACK_SIZE;
1414

1515
/* Linker script to configure memory regions. */
1616
MEMORY
17-
{
17+
{
1818
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
1919
SRAM2 (rwx) : ORIGIN = 0x10000188, LENGTH = 32k - 0x188
2020
SRAM1 (rwx) : ORIGIN = 0x20000000, LENGTH = 96k
@@ -24,7 +24,7 @@ MEMORY
2424
* with other linker script that defines memory regions FLASH and RAM.
2525
* It references following symbols, which must be defined in code:
2626
* Reset_Handler : Entry of reset handler
27-
*
27+
*
2828
* It defines following symbols, which code can use without definition:
2929
* __exidx_start
3030
* __exidx_end
@@ -92,81 +92,100 @@ SECTIONS
9292
__etext = .;
9393
_sidata = .;
9494

95+
/* .stack section doesn't contains any symbols. It is only
96+
* used for linker to reserve space for the isr stack section
97+
* WARNING: .stack should come immediately after the last secure memory
98+
* section. This provides stack overflow detection. */
99+
.stack (NOLOAD):
100+
{
101+
__StackLimit = .;
102+
*(.stack*);
103+
. += STACK_SIZE - (. - __StackLimit);
104+
} > SRAM2
105+
106+
/* Set stack top to end of RAM, and stack limit move down by
107+
* size of stack_dummy section */
108+
__StackTop = ADDR(.stack) + SIZEOF(.stack);
109+
_estack = __StackTop;
110+
__StackLimit = ADDR(.stack);
111+
PROVIDE(__stack = __StackTop);
112+
113+
/* Place holder for additional heap */
114+
.heap_0 (COPY):
115+
{
116+
__mbed_sbrk_start_0 = .;
117+
. += (ORIGIN(SRAM2) + LENGTH(SRAM2) - .);
118+
__mbed_krbs_start_0 = .;
119+
} > SRAM2
120+
121+
/* Check if heap exceeds SRAM2 */
122+
ASSERT(__mbed_krbs_start_0 <= (ORIGIN(SRAM2)+LENGTH(SRAM2)), "Heap is too big for SRAM2")
123+
95124
.data : AT (__etext)
96125
{
97126
__data_start__ = .;
98127
_sdata = .;
99128
*(vtable)
100129
*(.data*)
101130

102-
. = ALIGN(4);
131+
. = ALIGN(8);
103132
/* preinit data */
104133
PROVIDE_HIDDEN (__preinit_array_start = .);
105134
KEEP(*(.preinit_array))
106135
PROVIDE_HIDDEN (__preinit_array_end = .);
107136

108-
. = ALIGN(4);
137+
. = ALIGN(8);
109138
/* init data */
110139
PROVIDE_HIDDEN (__init_array_start = .);
111140
KEEP(*(SORT(.init_array.*)))
112141
KEEP(*(.init_array))
113142
PROVIDE_HIDDEN (__init_array_end = .);
114143

115-
116-
. = ALIGN(4);
144+
. = ALIGN(8);
117145
/* finit data */
118146
PROVIDE_HIDDEN (__fini_array_start = .);
119147
KEEP(*(SORT(.fini_array.*)))
120148
KEEP(*(.fini_array))
121149
PROVIDE_HIDDEN (__fini_array_end = .);
122150

123151
KEEP(*(.jcr*))
124-
. = ALIGN(4);
152+
. = ALIGN(8);
125153
/* All data end */
126154
__data_end__ = .;
127155
_edata = .;
128156

129157
} > SRAM1
130158

159+
/* Check if bss exceeds SRAM1 */
160+
ASSERT(__data_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), ".data is too big for SRAM1")
161+
131162
.bss :
132163
{
133-
. = ALIGN(4);
164+
. = ALIGN(8);
134165
__bss_start__ = .;
135166
_sbss = .;
136167
*(.bss*)
137168
*(COMMON)
138-
. = ALIGN(4);
169+
. = ALIGN(8);
139170
__bss_end__ = .;
140171
_ebss = .;
141172
} > SRAM1
142173

174+
/* Check if bss exceeds SRAM1 */
175+
ASSERT(__bss_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "BSS is too big for SRAM1")
176+
177+
/* Placeholder for default single heap */
143178
.heap (COPY):
144179
{
145180
__end__ = .;
146181
end = __end__;
182+
__mbed_sbrk_start = .;
147183
*(.heap*)
148184
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
185+
__mbed_krbs_start = .;
149186
__HeapLimit = .;
150187
} > SRAM1
151-
PROVIDE(__heap_size = SIZEOF(.heap));
152-
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
153-
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
154-
/* Check if data + heap exceeds RAM1 limit */
155-
ASSERT((ORIGIN(SRAM1)+LENGTH(SRAM1)) >= __HeapLimit, "SRAM1 overflow")
156-
/* .stack_dummy section doesn't contains any symbols. It is only
157-
* used for linker to calculate size of stack sections, and assign
158-
* values to stack symbols later */
159-
.stack_dummy (COPY):
160-
{
161-
*(.stack*)
162-
} > SRAM2
163188

164-
/* Set stack top to end of RAM, and stack limit move down by
165-
* size of stack_dummy section */
166-
__StackTop = ORIGIN(SRAM2) + LENGTH(SRAM2);
167-
_estack = __StackTop;
168-
__StackLimit = __StackTop - STACK_SIZE;
169-
PROVIDE(__stack = __StackTop);
170-
/* Check if stack exceeds RAM2 limit */
171-
ASSERT((ORIGIN(SRAM2)+LENGTH(SRAM2)) >= __StackLimit, "SRAM2 overflow")
172-
}
189+
/* Check if heap exceeds SRAM1 */
190+
ASSERT(__HeapLimit <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "Heap is too big for SRAM1")
191+
}

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L443xC/device/TOOLCHAIN_GCC_ARM/STM32L443XX.ld

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ SECTIONS
9393
__etext = .;
9494
_sidata = .;
9595

96+
/* .stack section doesn't contains any symbols. It is only
97+
* used for linker to reserve space for the isr stack section
98+
* WARNING: .stack should come immediately after the last secure memory
99+
* section. This provides stack overflow detection. */
100+
.stack (NOLOAD):
101+
{
102+
__StackLimit = .;
103+
*(.stack*);
104+
. += STACK_SIZE - (. - __StackLimit);
105+
} > SRAM2
106+
107+
/* Set stack top to end of RAM, and stack limit move down by
108+
* size of stack_dummy section */
109+
__StackTop = ADDR(.stack) + SIZEOF(.stack);
110+
_estack = __StackTop;
111+
__StackLimit = ADDR(.stack);
112+
PROVIDE(__stack = __StackTop);
113+
114+
/* Place holder for additional heap */
115+
.heap_0 (COPY):
116+
{
117+
__mbed_sbrk_start_0 = .;
118+
. += (ORIGIN(SRAM2) + LENGTH(SRAM2) - .);
119+
__mbed_krbs_start_0 = .;
120+
} > SRAM2
121+
122+
/* Check if heap exceeds SRAM2 */
123+
ASSERT(__mbed_krbs_start_0 <= (ORIGIN(SRAM2)+LENGTH(SRAM2)), "Heap is too big for SRAM2")
124+
96125
.data : AT (__etext)
97126
{
98127
__data_start__ = .;
@@ -129,6 +158,9 @@ SECTIONS
129158

130159
} > SRAM1
131160

161+
/* Check if bss exceeds SRAM1 */
162+
ASSERT(__data_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), ".data is too big for SRAM1")
163+
132164
.bss :
133165
{
134166
. = ALIGN(8);
@@ -141,30 +173,21 @@ SECTIONS
141173
_ebss = .;
142174
} > SRAM1
143175

176+
/* Check if bss exceeds SRAM1 */
177+
ASSERT(__bss_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "BSS is too big for SRAM1")
178+
179+
/* Placeholder for default single heap */
144180
.heap (COPY):
145181
{
146182
__end__ = .;
147183
end = __end__;
184+
__mbed_sbrk_start = .;
148185
*(.heap*)
149-
. = ORIGIN(SRAM1) + LENGTH(SRAM1) - STACK_SIZE;
186+
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
187+
__mbed_krbs_start = .;
150188
__HeapLimit = .;
151189
} > SRAM1
152190

153-
/* .stack_dummy section doesn't contains any symbols. It is only
154-
* used for linker to calculate size of stack sections, and assign
155-
* values to stack symbols later */
156-
.stack_dummy (COPY):
157-
{
158-
*(.stack*)
159-
} > SRAM1
160-
161-
/* Set stack top to end of RAM, and stack limit move down by
162-
* size of stack_dummy section */
163-
__StackTop = ORIGIN(SRAM1) + LENGTH(SRAM1);
164-
_estack = __StackTop;
165-
__StackLimit = __StackTop - STACK_SIZE;
166-
PROVIDE(__stack = __StackTop);
167-
168-
/* Check if data + heap + stack exceeds RAM limit */
169-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
191+
/* Check if heap exceeds SRAM1 */
192+
ASSERT(__HeapLimit <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "Heap is too big for SRAM1")
170193
}

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/device/TOOLCHAIN_GCC_ARM/STM32L476XX.ld

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,36 @@ SECTIONS
104104
. += M_CRASH_DATA_RAM_SIZE;
105105
. = ALIGN(8);
106106
__CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */
107-
} > SRAM1
107+
} > SRAM2
108+
109+
/* .stack section doesn't contains any symbols. It is only
110+
* used for linker to reserve space for the isr stack section
111+
* WARNING: .stack should come immediately after the last secure memory
112+
* section. This provides stack overflow detection. */
113+
.stack (NOLOAD):
114+
{
115+
__StackLimit = .;
116+
*(.stack*);
117+
. += STACK_SIZE - (. - __StackLimit);
118+
} > SRAM2
119+
120+
/* Set stack top to end of RAM, and stack limit move down by
121+
* size of stack_dummy section */
122+
__StackTop = ADDR(.stack) + SIZEOF(.stack);
123+
_estack = __StackTop;
124+
__StackLimit = ADDR(.stack);
125+
PROVIDE(__stack = __StackTop);
126+
127+
/* Place holder for additional heap */
128+
.heap_0 (COPY):
129+
{
130+
__mbed_sbrk_start_0 = .;
131+
. += (ORIGIN(SRAM2) + LENGTH(SRAM2) - .);
132+
__mbed_krbs_start_0 = .;
133+
} > SRAM2
134+
135+
/* Check if heap exceeds SRAM2 */
136+
ASSERT(__mbed_krbs_start_0 <= (ORIGIN(SRAM2)+LENGTH(SRAM2)), "Heap is too big for SRAM2")
108137

109138
.data : AT (__etext)
110139
{
@@ -126,7 +155,6 @@ SECTIONS
126155
KEEP(*(.init_array))
127156
PROVIDE_HIDDEN (__init_array_end = .);
128157

129-
130158
. = ALIGN(8);
131159
/* finit data */
132160
PROVIDE_HIDDEN (__fini_array_start = .);
@@ -142,6 +170,9 @@ SECTIONS
142170

143171
} > SRAM1
144172

173+
/* Check if bss exceeds SRAM1 */
174+
ASSERT(__data_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), ".data is too big for SRAM1")
175+
145176
.bss :
146177
{
147178
. = ALIGN(8);
@@ -154,34 +185,21 @@ SECTIONS
154185
_ebss = .;
155186
} > SRAM1
156187

188+
/* Check if bss exceeds SRAM1 */
189+
ASSERT(__bss_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "BSS is too big for SRAM1")
190+
191+
/* Placeholder for default single heap */
157192
.heap (COPY):
158193
{
159194
__end__ = .;
160195
end = __end__;
196+
__mbed_sbrk_start = .;
161197
*(.heap*)
162198
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
199+
__mbed_krbs_start = .;
163200
__HeapLimit = .;
164201
} > SRAM1
165-
PROVIDE(__heap_size = SIZEOF(.heap));
166-
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
167-
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
168-
/* Check if data + heap exceeds RAM1 limit */
169-
ASSERT((ORIGIN(SRAM1)+LENGTH(SRAM1)) >= __HeapLimit, "SRAM1 overflow")
170-
/* .stack_dummy section doesn't contains any symbols. It is only
171-
* used for linker to calculate size of stack sections, and assign
172-
* values to stack symbols later */
173-
.stack_dummy (COPY):
174-
{
175-
*(.stack*)
176-
} > SRAM2
177-
178-
/* Set stack top to end of RAM, and stack limit move down by
179-
* size of stack_dummy section */
180-
__StackTop = ORIGIN(SRAM2) + LENGTH(SRAM2);
181-
_estack = __StackTop;
182-
__StackLimit = __StackTop - STACK_SIZE;
183-
PROVIDE(__stack = __StackTop);
184-
/* Check if stack exceeds RAM2 limit */
185-
ASSERT((ORIGIN(SRAM2)+LENGTH(SRAM2)) >= __StackLimit, "SRAM2 overflow")
186202

203+
/* Check if heap exceeds SRAM1 */
204+
ASSERT(__HeapLimit <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "Heap is too big for SRAM1")
187205
}

0 commit comments

Comments
 (0)