Skip to content

Commit 02b2b01

Browse files
committed
Change STM32L475/76/86 GCC_ARM linker files to have HEAP in SRAM1 and stack in SRAM2 (after the interrupt vector)
1 parent 0efc876 commit 02b2b01

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,29 @@ SECTIONS
139139
__end__ = .;
140140
end = __end__;
141141
*(.heap*)
142+
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
142143
__HeapLimit = .;
143144
} > SRAM1
144-
145+
PROVIDE(__heap_size = SIZEOF(.heap));
146+
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
147+
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
148+
/* Check if data + heap exceeds RAM1 limit */
149+
ASSERT((ORIGIN(SRAM1)+LENGTH(SRAM1)) >= __HeapLimit, "SRAM1 overflow")
145150
/* .stack_dummy section doesn't contains any symbols. It is only
146151
* used for linker to calculate size of stack sections, and assign
147152
* values to stack symbols later */
148153
.stack_dummy (COPY):
149154
{
150155
*(.stack*)
151-
} > SRAM1
156+
} > SRAM2
152157

153158
/* Set stack top to end of RAM, and stack limit move down by
154159
* size of stack_dummy section */
155-
__StackTop = ORIGIN(SRAM1) + LENGTH(SRAM1);
160+
__StackTop = ORIGIN(SRAM2) + LENGTH(SRAM2);
156161
_estack = __StackTop;
157162
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
158163
PROVIDE(__stack = __StackTop);
164+
/* Check if stack exceeds RAM2 limit */
165+
ASSERT((ORIGIN(SRAM2)+LENGTH(SRAM2)) >= __StackLimit, "SRAM2 overflow")
159166

160-
/* Check if data + heap + stack exceeds RAM limit */
161-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
162167
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,29 @@ SECTIONS
139139
__end__ = .;
140140
end = __end__;
141141
*(.heap*)
142+
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
142143
__HeapLimit = .;
143144
} > SRAM1
144-
145+
PROVIDE(__heap_size = SIZEOF(.heap));
146+
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
147+
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
148+
/* Check if data + heap exceeds RAM1 limit */
149+
ASSERT((ORIGIN(SRAM1)+LENGTH(SRAM1)) >= __HeapLimit, "SRAM1 overflow")
145150
/* .stack_dummy section doesn't contains any symbols. It is only
146151
* used for linker to calculate size of stack sections, and assign
147152
* values to stack symbols later */
148153
.stack_dummy (COPY):
149154
{
150155
*(.stack*)
151-
} > SRAM1
156+
} > SRAM2
152157

153158
/* Set stack top to end of RAM, and stack limit move down by
154159
* size of stack_dummy section */
155-
__StackTop = ORIGIN(SRAM1) + LENGTH(SRAM1);
160+
__StackTop = ORIGIN(SRAM2) + LENGTH(SRAM2);
156161
_estack = __StackTop;
157162
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
158163
PROVIDE(__stack = __StackTop);
164+
/* Check if stack exceeds RAM2 limit */
165+
ASSERT((ORIGIN(SRAM2)+LENGTH(SRAM2)) >= __StackLimit, "SRAM2 overflow")
159166

160-
/* Check if data + heap + stack exceeds RAM limit */
161-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
162167
}

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/device/TOOLCHAIN_GCC_ARM/STM32L486XX.ld

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,29 @@ SECTIONS
131131
__end__ = .;
132132
end = __end__;
133133
*(.heap*)
134+
. += (ORIGIN(SRAM1) + LENGTH(SRAM1) - .);
134135
__HeapLimit = .;
135136
} > SRAM1
136-
137+
PROVIDE(__heap_size = SIZEOF(.heap));
138+
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
139+
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
140+
/* Check if data + heap exceeds RAM1 limit */
141+
ASSERT((ORIGIN(SRAM1)+LENGTH(SRAM1)) >= __HeapLimit, "SRAM1 overflow")
137142
/* .stack_dummy section doesn't contains any symbols. It is only
138143
* used for linker to calculate size of stack sections, and assign
139144
* values to stack symbols later */
140145
.stack_dummy (COPY):
141146
{
142147
*(.stack*)
143-
} > SRAM1
148+
} > SRAM2
144149

145150
/* Set stack top to end of RAM, and stack limit move down by
146151
* size of stack_dummy section */
147-
__StackTop = ORIGIN(SRAM1) + LENGTH(SRAM1);
152+
__StackTop = ORIGIN(SRAM2) + LENGTH(SRAM2);
148153
_estack = __StackTop;
149154
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
150155
PROVIDE(__stack = __StackTop);
156+
/* Check if stack exceeds RAM2 limit */
157+
ASSERT((ORIGIN(SRAM2)+LENGTH(SRAM2)) >= __StackLimit, "SRAM2 overflow")
151158

152-
/* Check if data + heap + stack exceeds RAM limit */
153-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
154159
}

0 commit comments

Comments
 (0)