Skip to content

Commit b57b12c

Browse files
committed
STM32L0 baremetal support
1 parent 9b819c7 commit b57b12c

File tree

8 files changed

+335
-241
lines changed

8 files changed

+335
-241
lines changed
Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,53 @@
11
#! armcc -E
22
; Scatter-Loading Description File
3-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4-
; Copyright (c) 2015, STMicroelectronics
5-
; All rights reserved.
63
;
7-
; Redistribution and use in source and binary forms, with or without
8-
; modification, are permitted provided that the following conditions are met:
9-
;
10-
; 1. Redistributions of source code must retain the above copyright notice,
11-
; this list of conditions and the following disclaimer.
12-
; 2. Redistributions in binary form must reproduce the above copyright notice,
13-
; this list of conditions and the following disclaimer in the documentation
14-
; and/or other materials provided with the distribution.
15-
; 3. Neither the name of STMicroelectronics nor the names of its contributors
16-
; may be used to endorse or promote products derived from this software
17-
; without specific prior written permission.
18-
;
19-
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20-
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21-
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22-
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23-
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24-
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25-
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26-
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27-
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28-
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4+
; SPDX-License-Identifier: BSD-3-Clause
5+
;******************************************************************************
6+
;* @attention
7+
;*
8+
;* Copyright (c) 2016-2020 STMicroelectronics.
9+
;* All rights reserved.
10+
;*
11+
;* This software component is licensed by ST under BSD 3-Clause license,
12+
;* the "License"; You may not use this file except in compliance with the
13+
;* License. You may obtain a copy of the License at:
14+
;* opensource.org/licenses/BSD-3-Clause
15+
;*
16+
;******************************************************************************
17+
18+
#include "../cmsis_nvic.h"
3019

3120
#if !defined(MBED_APP_START)
32-
#define MBED_APP_START 0x08000000
21+
#define MBED_APP_START MBED_ROM_START
3322
#endif
3423

35-
; STM32L073RZ: 192KB FLASH (0x30000)
3624
#if !defined(MBED_APP_SIZE)
37-
#define MBED_APP_SIZE 0x30000
38-
#endif
39-
40-
; 20KB RAM (0x5000)
41-
#if !defined(MBED_RAM_START)
42-
#define MBED_RAM_START 0x20000000
25+
#define MBED_APP_SIZE MBED_ROM_SIZE
4326
#endif
4427

45-
#if !defined(MBED_RAM_SIZE)
46-
#define MBED_RAM_SIZE 0x5000
47-
#endif
48-
49-
5028
#if !defined(MBED_BOOT_STACK_SIZE)
51-
#define MBED_BOOT_STACK_SIZE 0x400
29+
/* This value is normally defined by the tools to 0x1000 for bare metal and 0x400 for RTOS */
30+
#define MBED_BOOT_STACK_SIZE 0x400
5231
#endif
5332

54-
; Total: 48 vectors = 192 bytes (0xC0) to be reserved in RAM
55-
#define VECTOR_SIZE 0xC0
56-
57-
#define RAM_FIXED_SIZE (MBED_BOOT_STACK_SIZE+VECTOR_SIZE)
33+
/* Round up VECTORS_SIZE to 8 bytes */
34+
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) AND ~7)
5835

59-
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
36+
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
6037

61-
ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address
62-
*.o (RESET, +First)
63-
*(InRoot$$Sections)
64-
.ANY (+RO)
38+
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
39+
*.o (RESET, +First)
40+
*(InRoot$$Sections)
41+
.ANY (+RO)
6542
}
6643

67-
RW_IRAM1 (MBED_RAM_START+VECTOR_SIZE) (MBED_RAM_SIZE-VECTOR_SIZE) { ; RW data
68-
.ANY (+RW +ZI)
44+
RW_IRAM1 (MBED_RAM_START + VECTORS_SIZE) { ; RW data
45+
.ANY (+RW +ZI)
6946
}
7047

71-
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_SIZE-RAM_FIXED_SIZE+MBED_RAM_START-AlignExpr(ImageLimit(RW_IRAM1), 16)) {
48+
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_START + MBED_RAM_SIZE - MBED_BOOT_STACK_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) { ; Heap growing up
7249
}
7350

74-
ARM_LIB_STACK (MBED_RAM_START+MBED_RAM_SIZE) EMPTY -MBED_BOOT_STACK_SIZE { ; stack
51+
ARM_LIB_STACK (MBED_RAM_START + MBED_RAM_SIZE) EMPTY -MBED_BOOT_STACK_SIZE { ; Stack region growing down
7552
}
7653
}

targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/TOOLCHAIN_GCC_ARM/STM32L073XZ.ld

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
/* Linker script to configure memory regions. */
2+
/*
3+
* SPDX-License-Identifier: BSD-3-Clause
4+
******************************************************************************
5+
* @attention
6+
*
7+
* Copyright (c) 2016-2020 STMicroelectronics.
8+
* All rights reserved.
9+
*
10+
* This software component is licensed by ST under BSD 3-Clause license,
11+
* the "License"; You may not use this file except in compliance with the
12+
* License. You may obtain a copy of the License at:
13+
* opensource.org/licenses/BSD-3-Clause
14+
*
15+
******************************************************************************
16+
*/
17+
18+
#include "../cmsis_nvic.h"
19+
20+
21+
#if !defined(MBED_APP_START)
22+
#define MBED_APP_START MBED_ROM_START
23+
#endif
24+
25+
#if !defined(MBED_APP_SIZE)
26+
#define MBED_APP_SIZE MBED_ROM_SIZE
27+
#endif
28+
29+
#if !defined(MBED_BOOT_STACK_SIZE)
30+
/* This value is normally defined by the tools
31+
to 0x1000 for bare metal and 0x400 for RTOS */
32+
#define MBED_BOOT_STACK_SIZE 0x400
33+
#endif
34+
35+
/* Round up VECTORS_SIZE to 8 bytes */
36+
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8)
37+
38+
MEMORY
39+
{
40+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
41+
RAM (rwx) : ORIGIN = MBED_RAM_START + VECTORS_SIZE, LENGTH = MBED_RAM_SIZE - VECTORS_SIZE
42+
}
43+
144
/* Linker script to place sections and symbol values. Should be used together
245
* with other linker script that defines memory regions FLASH and RAM.
346
* It references following symbols, which must be defined in code:
@@ -25,28 +68,6 @@
2568
* __stack
2669
* _estack
2770
*/
28-
29-
#if !defined(MBED_APP_START)
30-
#define MBED_APP_START 0x08000000
31-
#endif
32-
33-
#if !defined(MBED_APP_SIZE)
34-
#define MBED_APP_SIZE 0x30000
35-
#endif
36-
37-
#if !defined(MBED_BOOT_STACK_SIZE)
38-
#define MBED_BOOT_STACK_SIZE 0x400
39-
#endif
40-
41-
STACK_SIZE = MBED_BOOT_STACK_SIZE;
42-
43-
/* Linker script to configure memory regions. */
44-
MEMORY
45-
{
46-
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
47-
RAM (rwx) : ORIGIN = 0x200000C0, LENGTH = 20K - 0xC0
48-
}
49-
5071
ENTRY(Reset_Handler)
5172

5273
SECTIONS
@@ -55,6 +76,7 @@ SECTIONS
5576
{
5677
KEEP(*(.isr_vector))
5778
*(.text*)
79+
5880
KEEP(*(.init))
5981
KEEP(*(.fini))
6082

@@ -77,7 +99,7 @@ SECTIONS
7799
KEEP(*(.eh_frame*))
78100
} > FLASH
79101

80-
.ARM.extab :
102+
.ARM.extab :
81103
{
82104
*(.ARM.extab* .gnu.linkonce.armextab.*)
83105
} > FLASH
@@ -91,7 +113,7 @@ SECTIONS
91113

92114
__etext = .;
93115
_sidata = .;
94-
116+
95117
.data : AT (__etext)
96118
{
97119
__data_start__ = .;
@@ -112,7 +134,6 @@ SECTIONS
112134
KEEP(*(.init_array))
113135
PROVIDE_HIDDEN (__init_array_end = .);
114136

115-
116137
. = ALIGN(8);
117138
/* finit data */
118139
PROVIDE_HIDDEN (__fini_array_start = .);
@@ -128,6 +149,19 @@ SECTIONS
128149

129150
} > RAM
130151

152+
/* Uninitialized data section
153+
* This region is not initialized by the C/C++ library and can be used to
154+
* store state across soft reboots. */
155+
.uninitialized (NOLOAD):
156+
{
157+
. = ALIGN(32);
158+
__uninitialized_start = .;
159+
*(.uninitialized)
160+
KEEP(*(.keep.uninitialized))
161+
. = ALIGN(32);
162+
__uninitialized_end = .;
163+
} > RAM
164+
131165
.bss :
132166
{
133167
. = ALIGN(8);
@@ -143,9 +177,9 @@ SECTIONS
143177
.heap (COPY):
144178
{
145179
__end__ = .;
146-
end = __end__;
180+
PROVIDE(end = .);
147181
*(.heap*)
148-
. = ORIGIN(RAM) + LENGTH(RAM) - STACK_SIZE;
182+
. = ORIGIN(RAM) + LENGTH(RAM) - MBED_BOOT_STACK_SIZE;
149183
__HeapLimit = .;
150184
} > RAM
151185

@@ -161,7 +195,7 @@ SECTIONS
161195
* size of stack_dummy section */
162196
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
163197
_estack = __StackTop;
164-
__StackLimit = __StackTop - STACK_SIZE;
198+
__StackLimit = __StackTop - MBED_BOOT_STACK_SIZE;
165199
PROVIDE(__stack = __StackTop);
166200

167201
/* Check if data + heap + stack exceeds RAM limit */
Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
1-
if (!isdefinedsymbol(MBED_APP_START)) {
2-
define symbol MBED_APP_START = 0x08000000;
1+
/* Linker script to configure memory regions.
2+
*
3+
* SPDX-License-Identifier: BSD-3-Clause
4+
******************************************************************************
5+
* @attention
6+
*
7+
* Copyright (c) 2016-2020 STMicroelectronics.
8+
* All rights reserved.
9+
*
10+
* This software component is licensed by ST under BSD 3-Clause license,
11+
* the "License"; You may not use this file except in compliance with the
12+
* License. You may obtain a copy of the License at:
13+
* opensource.org/licenses/BSD-3-Clause
14+
*
15+
******************************************************************************
16+
*/
17+
/* Device specific values */
18+
19+
/* Tools provide -DMBED_ROM_START=xxx -DMBED_ROM_SIZE=xxx -DMBED_RAM_START=xxx -DMBED_RAM_SIZE=xxx */
20+
21+
define symbol VECTORS = 48; /* This value must match NVIC_NUM_VECTORS in cmsis_nvic.h */
22+
define symbol HEAP_SIZE = 0x1000;
23+
24+
/* Common - Do not change */
25+
26+
if (!isdefinedsymbol(MBED_APP_START)) {
27+
define symbol MBED_APP_START = MBED_ROM_START;
328
}
429

5-
if (!isdefinedsymbol(MBED_APP_SIZE)) {
6-
define symbol MBED_APP_SIZE = 0x30000;
30+
if (!isdefinedsymbol(MBED_APP_SIZE)) {
31+
define symbol MBED_APP_SIZE = MBED_ROM_SIZE;
732
}
833

9-
define symbol __intvec_start__ = MBED_APP_START;
10-
define symbol __region_ROM_start__ = MBED_APP_START;
11-
define symbol __region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
34+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
35+
/* This value is normally defined by the tools
36+
to 0x1000 for bare metal and 0x400 for RTOS */
37+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
38+
}
1239

13-
/* [RAM = 20kb = 0x5000] Vector table dynamic copy: 48 vectors = 192 bytes (0xC0) to be reserved in RAM */
14-
define symbol __NVIC_start__ = 0x20000000;
15-
define symbol __NVIC_end__ = 0x200000BF; /* Aligned on 8 bytes */
16-
define symbol __region_RAM_start__ = 0x200000C0;
17-
define symbol __region_RAM_end__ = 0x20004FFF;
40+
/* Round up VECTORS_SIZE to 8 bytes */
41+
define symbol VECTORS_SIZE = ((VECTORS * 4) + 7) & ~7;
42+
define symbol RAM_REGION_START = MBED_RAM_START + VECTORS_SIZE;
43+
define symbol RAM_REGION_SIZE = MBED_RAM_SIZE - VECTORS_SIZE;
1844

19-
/* Memory regions */
2045
define memory mem with size = 4G;
21-
define region ROM_region = mem:[from __region_ROM_start__ to __region_ROM_end__];
22-
define region RAM_region = mem:[from __region_RAM_start__ to __region_RAM_end__];
46+
define region ROM_region = mem:[from MBED_APP_START size MBED_APP_SIZE];
47+
define region RAM_region = mem:[from RAM_REGION_START size RAM_REGION_SIZE];
2348

24-
/* Stack and Heap */
25-
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
26-
define symbol MBED_BOOT_STACK_SIZE = 0x400;
27-
}
28-
define symbol __size_cstack__ = MBED_BOOT_STACK_SIZE;
29-
define symbol __size_heap__ = 0x1000;
30-
define block CSTACK with alignment = 8, size = __size_cstack__ { };
31-
define block HEAP with alignment = 8, size = __size_heap__ { };
32-
define block STACKHEAP with fixed order { block HEAP, block CSTACK };
49+
define block CSTACK with alignment = 8, size = MBED_BOOT_STACK_SIZE { };
50+
define block HEAP with alignment = 8, size = HEAP_SIZE { };
3351

34-
initialize by copy with packing = zeros { readwrite };
52+
initialize by copy { readwrite };
3553
do not initialize { section .noinit };
3654

37-
place at address mem:__intvec_start__ { readonly section .intvec };
55+
place at address mem: MBED_APP_START { readonly section .intvec };
3856

3957
place in ROM_region { readonly };
40-
place in RAM_region { readwrite, block STACKHEAP };
58+
place in RAM_region { readwrite,
59+
block CSTACK, block HEAP };

0 commit comments

Comments
 (0)