Skip to content

Commit 58975d1

Browse files
authored
Merge pull request #13091 from jeromecoutant/PR_BAREMETAL_SUPPORT
STM32 baremetal support step3/3 (F2/F4)
2 parents d0d35c2 + 713618a commit 58975d1

File tree

47 files changed

+1561
-1117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1561
-1117
lines changed
Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,53 @@
11
#! armcc -E
22
; Scatter-Loading Description File
3-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4-
; Copyright (c) 2016, 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

3524
#if !defined(MBED_APP_SIZE)
36-
#define MBED_APP_SIZE 0x100000
37-
#endif
38-
39-
#if !defined(MBED_RAM_START)
40-
#define MBED_RAM_START 0x20000000
25+
#define MBED_APP_SIZE MBED_ROM_SIZE
4126
#endif
4227

43-
#if !defined(MBED_RAM_SIZE)
44-
#define MBED_RAM_SIZE 0x00020000
45-
#endif
46-
47-
4828
#if !defined(MBED_BOOT_STACK_SIZE)
49-
#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
5031
#endif
5132

52-
; 97 vectors * 4 bytes = 388 bytes to reserve (0x184) 8-byte aligned = 0x188 (0x184 + 0x4)
53-
#define VECTOR_SIZE 0x188
54-
55-
#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)
5635

57-
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
36+
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
5837

59-
ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address
60-
*.o (RESET, +First)
61-
*(InRoot$$Sections)
62-
.ANY (+RO)
38+
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
39+
*.o (RESET, +First)
40+
*(InRoot$$Sections)
41+
.ANY (+RO)
6342
}
6443

65-
RW_IRAM1 (MBED_RAM_START+VECTOR_SIZE) (MBED_RAM_SIZE-VECTOR_SIZE) { ; RW data
66-
.ANY (+RW +ZI)
44+
RW_IRAM1 (MBED_RAM_START + VECTORS_SIZE) { ; RW data
45+
.ANY (+RW +ZI)
6746
}
6847

69-
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
7049
}
7150

72-
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
7352
}
7453
}

targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/TOOLCHAIN_GCC_ARM/STM32F207ZGTx_FLASH.ld

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
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+
121
#if !defined(MBED_APP_START)
2-
#define MBED_APP_START 0x8000000
22+
#define MBED_APP_START MBED_ROM_START
323
#endif
424

525
#if !defined(MBED_APP_SIZE)
6-
#define MBED_APP_SIZE 1024k
26+
#define MBED_APP_SIZE MBED_ROM_SIZE
727
#endif
828

929
#if !defined(MBED_BOOT_STACK_SIZE)
10-
#define MBED_BOOT_STACK_SIZE 0x400
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
1133
#endif
1234

13-
STACK_SIZE = MBED_BOOT_STACK_SIZE;
35+
/* Round up VECTORS_SIZE to 8 bytes */
36+
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8)
1437

15-
/* Linker script to configure memory regions. */
16-
/* 97 vectors * 4 bytes = 388 bytes to reserve (0x184) */
17-
/* 8-byte aligned(0x184) = 0x188 */
1838
MEMORY
1939
{
20-
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
21-
RAM (rwx) : ORIGIN = 0x20000188, LENGTH = 128K - 0x188
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
2242
}
2343

2444
/* Linker script to place sections and symbol values. Should be used together
@@ -56,6 +76,7 @@ SECTIONS
5676
{
5777
KEEP(*(.isr_vector))
5878
*(.text*)
79+
5980
KEEP(*(.init))
6081
KEEP(*(.fini))
6182

@@ -92,7 +113,7 @@ SECTIONS
92113

93114
__etext = .;
94115
_sidata = .;
95-
116+
96117
.data : AT (__etext)
97118
{
98119
__data_start__ = .;
@@ -113,7 +134,6 @@ SECTIONS
113134
KEEP(*(.init_array))
114135
PROVIDE_HIDDEN (__init_array_end = .);
115136

116-
117137
. = ALIGN(8);
118138
/* finit data */
119139
PROVIDE_HIDDEN (__fini_array_start = .);
@@ -129,6 +149,19 @@ SECTIONS
129149

130150
} > RAM
131151

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+
132165
.bss :
133166
{
134167
. = ALIGN(8);
@@ -144,9 +177,9 @@ SECTIONS
144177
.heap (COPY):
145178
{
146179
__end__ = .;
147-
end = __end__;
180+
PROVIDE(end = .);
148181
*(.heap*)
149-
. = ORIGIN(RAM) + LENGTH(RAM) - STACK_SIZE;
182+
. = ORIGIN(RAM) + LENGTH(RAM) - MBED_BOOT_STACK_SIZE;
150183
__HeapLimit = .;
151184
} > RAM
152185

@@ -162,7 +195,7 @@ SECTIONS
162195
* size of stack_dummy section */
163196
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
164197
_estack = __StackTop;
165-
__StackLimit = __StackTop - STACK_SIZE;
198+
__StackLimit = __StackTop - MBED_BOOT_STACK_SIZE;
166199
PROVIDE(__stack = __StackTop);
167200

168201
/* Check if data + heap + stack exceeds RAM limit */
Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
1-
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x08000000; }
2-
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x100000; }
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 */
318

4-
/* [ROM = 1024kb = 0x100000] */
5-
define symbol __intvec_start__ = MBED_APP_START;
6-
define symbol __region_ROM_start__ = 0x08000000;
7-
define symbol __region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
19+
/* Tools provide -DMBED_ROM_START=xxx -DMBED_ROM_SIZE=xxx -DMBED_RAM_START=xxx -DMBED_RAM_SIZE=xxx */
820

9-
/* [RAM = 128kb = 0x20000] Vector table dynamic copy: 97 vectors = 388 bytes (0x184) to be reserved in RAM */
10-
define symbol __NVIC_start__ = 0x20000000;
11-
define symbol __NVIC_end__ = 0x20000187; /*aligned on 8 bytes */
12-
define symbol __region_RAM_start__ = 0x20000188;
13-
define symbol __region_RAM_end__ = 0x2001FFFF;
21+
define symbol VECTORS = 97; /* This value must match NVIC_NUM_VECTORS in cmsis_nvic.h */
22+
define symbol HEAP_SIZE = 0xa000;
1423

15-
/* Memory regions */
16-
define memory mem with size = 4G;
17-
define region ROM_region = mem:[from __region_ROM_start__ to __region_ROM_end__];
18-
define region RAM_region = mem:[from __region_RAM_start__ to __region_RAM_end__];
24+
/* Common - Do not change */
25+
26+
if (!isdefinedsymbol(MBED_APP_START)) {
27+
define symbol MBED_APP_START = MBED_ROM_START;
28+
}
29+
30+
if (!isdefinedsymbol(MBED_APP_SIZE)) {
31+
define symbol MBED_APP_SIZE = MBED_ROM_SIZE;
32+
}
1933

20-
/* Stack and Heap */
2134
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 */
2237
define symbol MBED_BOOT_STACK_SIZE = 0x400;
2338
}
24-
define symbol __size_cstack__ = MBED_BOOT_STACK_SIZE;
25-
define symbol __size_heap__ = 0xF000;
26-
define block CSTACK with alignment = 8, size = __size_cstack__ { };
27-
define block HEAP with alignment = 8, size = __size_heap__ { };
28-
define block STACKHEAP with fixed order { block HEAP, block CSTACK };
2939

30-
initialize by copy with packing = zeros { readwrite };
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;
44+
45+
define memory mem with size = 4G;
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];
48+
49+
define block CSTACK with alignment = 8, size = MBED_BOOT_STACK_SIZE { };
50+
define block HEAP with alignment = 8, size = HEAP_SIZE { };
51+
52+
initialize by copy { readwrite };
3153
do not initialize { section .noinit };
3254

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

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

3117
#ifndef MBED_CMSIS_NVIC_H
3218
#define MBED_CMSIS_NVIC_H
3319

34-
// CORE: 16 vectors (= 64 bytes from 0x00 to 0x3F)
35-
// MCU Peripherals: 81 vectors
36-
// Total: 388 bytes to be reserved in RAM (see scatter file)
20+
#if !defined(MBED_ROM_START)
21+
#define MBED_ROM_START 0x8000000
22+
#endif
23+
24+
#if !defined(MBED_ROM_SIZE)
25+
#define MBED_ROM_SIZE 0x100000 // 1.0 MB
26+
#endif
27+
28+
#if !defined(MBED_RAM_START)
29+
#define MBED_RAM_START 0x20000000
30+
#endif
31+
32+
#if !defined(MBED_RAM_SIZE)
33+
#define MBED_RAM_SIZE 0x20000 // 128 KB
34+
#endif
35+
3736
#define NVIC_NUM_VECTORS 97
38-
#define NVIC_RAM_VECTOR_ADDRESS 0x20000000 // Vectors positioned at start of RAM
37+
#define NVIC_RAM_VECTOR_ADDRESS MBED_RAM_START
3938

4039
#endif

0 commit comments

Comments
 (0)