Skip to content

Commit 719d0fb

Browse files
author
Deepika
committed
Update linker script for split heap support
To have the flexibilty in application; to use any of the section (data/bss/heap) without updating linker script in every use case, following decisions are made: 1. Fixed size and small sections moved to SRAM2 (32K) Vectors Crash data Stack Remaining section - Heap memory 2. Large memory space should be used for variable sections Data BSS Heap - Remaining section Heap is moved to the end of both sections as GCC allocates till 4K boundary, if end of heap is not aligned to 4K, that chunk of memory will go unutilized
1 parent 7c07141 commit 719d0fb

File tree

1 file changed

+32
-32
lines changed
  • targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/device/TOOLCHAIN_GCC_ARM

1 file changed

+32
-32
lines changed

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/device/TOOLCHAIN_GCC_ARM/STM32L475XX.ld

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,25 @@ 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);
108126

109127
.data : AT (__etext)
110128
{
@@ -126,7 +144,6 @@ SECTIONS
126144
KEEP(*(.init_array))
127145
PROVIDE_HIDDEN (__init_array_end = .);
128146

129-
130147
. = ALIGN(8);
131148
/* finit data */
132149
PROVIDE_HIDDEN (__fini_array_start = .);
@@ -139,9 +156,11 @@ SECTIONS
139156
/* All data end */
140157
__data_end__ = .;
141158
_edata = .;
142-
143159
} > SRAM1
144160

161+
/* Check if bss exceeds SRAM1 */
162+
ASSERT(__data_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), ".data is too big for SRAM1")
163+
145164
.bss :
146165
{
147166
. = ALIGN(8);
@@ -152,41 +171,22 @@ SECTIONS
152171
. = ALIGN(8);
153172
__bss_end__ = .;
154173
_ebss = .;
155-
} > SRAM2
174+
} > SRAM1
175+
176+
/* Check if bss exceeds SRAM1 */
177+
ASSERT(__bss_end__ <= (ORIGIN(SRAM1)+LENGTH(SRAM1)), "BSS is too big for SRAM1")
156178

157179
.heap (COPY):
158180
{
159181
__end__ = .;
182+
__mbed_sbrk_start_0 = .;
160183
end = __end__;
161184
*(.heap*)
162-
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
163-
__HeapLimit = .;
164-
} > 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-
. += (ORIGIN(SRAM2) + STACK_SIZE - .);
177-
__mbed_sbrk_start_0 = .;
178-
. += (ORIGIN(SRAM2) + LENGTH(SRAM2) - .);
185+
. = (ORIGIN(SRAM2) + LENGTH(SRAM2));
179186
__mbed_krbs_start_0 = .;
187+
__mbed_sbrk_start = __bss_end__;
188+
. = (ORIGIN(SRAM1) + LENGTH(SRAM1));
189+
__mbed_krbs_start = .;
190+
__HeapLimit = .;
180191
} > SRAM2
181-
182-
/* Set stack top to end of RAM, and stack limit move down by
183-
* size of stack_dummy section */
184-
__StackTop = ORIGIN(SRAM2) + LENGTH(SRAM2);
185-
_estack = __StackTop;
186-
__StackLimit = __StackTop - STACK_SIZE;
187-
PROVIDE(__stack = __StackTop);
188-
/* Check if stack exceeds RAM2 limit */
189-
ASSERT((ORIGIN(SRAM2)+LENGTH(SRAM2)) >= __StackLimit, "SRAM2 overflow")
190-
/* Check if bss exceeds __StackLimit */
191-
ASSERT(__bss_end__ <= __StackLimit, "BSS is too big for RAM2")
192192
}

0 commit comments

Comments
 (0)