Skip to content

Commit ed0cadf

Browse files
authored
Merge pull request #12992 from jeromecoutant/PR_BAREMETAL_SUPPORT_STEP1
STM32 baremetal support step1 (F0/F1/F3/H7/L0)
2 parents 096b3e8 + b57b12c commit ed0cadf

File tree

44 files changed

+1555
-1085
lines changed

Some content is hidden

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

44 files changed

+1555
-1085
lines changed
Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
11
#! armcc -E
22
; Scatter-Loading Description File
3-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4-
; Copyright (c) 2014, 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) 2014-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+
#if !defined(MBED_APP_START)
19+
#define MBED_APP_START MBED_ROM_START
20+
#endif
21+
22+
#if !defined(MBED_APP_SIZE)
23+
#define MBED_APP_SIZE MBED_ROM_SIZE
24+
#endif
3025

3126
#if !defined(MBED_BOOT_STACK_SIZE)
32-
#define MBED_BOOT_STACK_SIZE 0x400
27+
/* This value is normally defined by the tools to 0x1000 for bare metal and 0x400 for RTOS */
28+
#define MBED_BOOT_STACK_SIZE 0x400
3329
#endif
3430

35-
#define Stack_Size MBED_BOOT_STACK_SIZE
31+
/* Round up VECTORS_SIZE to 8 bytes */
32+
#define NVIC_NUM_VECTORS 48
33+
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) AND ~7)
3634

37-
; STM32F070RB: 128KB FLASH (0x20000) + 16KB RAM (0x4000)
35+
LR_IROM1 MBED_APP_START MBED_APP_SIZE {
3836

39-
LR_IROM1 0x08000000 0x20000 { ; load region size_region
40-
ER_IROM1 0x08000000 0x20000 { ; load address = execution address
41-
*.o (RESET, +First)
42-
*(InRoot$$Sections)
43-
.ANY (+RO)
37+
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
38+
*.o (RESET, +First)
39+
*(InRoot$$Sections)
40+
.ANY (+RO)
4441
}
4542

46-
; 48 vectors = 192 bytes (0xC0) to be reserved in RAM
47-
RW_IRAM1 (0x20000000+0xC0) (0x4000-0xC0-Stack_Size) { ; RW data
48-
.ANY (+RW +ZI)
43+
RW_IRAM1 (MBED_RAM_START + VECTORS_SIZE) { ; RW data
44+
.ANY (+RW +ZI)
4945
}
5046

51-
ARM_LIB_STACK (0x20000000+0x4000) EMPTY -Stack_Size { ; stack
47+
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
5248
}
53-
}
5449

50+
ARM_LIB_STACK (MBED_RAM_START + MBED_RAM_SIZE) EMPTY -MBED_BOOT_STACK_SIZE { ; Stack region growing down
51+
}
52+
}

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/TOOLCHAIN_GCC_ARM/STM32F070XB.ld

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
/* 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+
19+
#if !defined(MBED_APP_START)
20+
#define MBED_APP_START MBED_ROM_START
21+
#endif
22+
23+
#if !defined(MBED_APP_SIZE)
24+
#define MBED_APP_SIZE MBED_ROM_SIZE
25+
#endif
226

327
#if !defined(MBED_BOOT_STACK_SIZE)
4-
#define MBED_BOOT_STACK_SIZE 0x400
28+
/* This value is normally defined by the tools
29+
to 0x1000 for bare metal and 0x400 for RTOS */
30+
#define MBED_BOOT_STACK_SIZE 0x400
531
#endif
632

7-
StackSize = MBED_BOOT_STACK_SIZE;
33+
/* Round up VECTORS_SIZE to 8 bytes */
34+
#define NVIC_NUM_VECTORS 48
35+
#define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8)
836

937
MEMORY
10-
{
11-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128k
12-
RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 16k - 0x0C0
38+
{
39+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
40+
RAM (rwx) : ORIGIN = MBED_RAM_START + VECTORS_SIZE, LENGTH = MBED_RAM_SIZE - VECTORS_SIZE
1341
}
1442

1543
/* Linker script to place sections and symbol values. Should be used together
1644
* with other linker script that defines memory regions FLASH and RAM.
1745
* It references following symbols, which must be defined in code:
1846
* Reset_Handler : Entry of reset handler
19-
*
47+
*
2048
* It defines following symbols, which code can use without definition:
2149
* __exidx_start
2250
* __exidx_end
@@ -47,6 +75,7 @@ SECTIONS
4775
{
4876
KEEP(*(.isr_vector))
4977
*(.text*)
78+
5079
KEEP(*(.init))
5180
KEEP(*(.fini))
5281

@@ -83,7 +112,7 @@ SECTIONS
83112

84113
__etext = .;
85114
_sidata = .;
86-
115+
87116
.data : AT (__etext)
88117
{
89118
__data_start__ = .;
@@ -104,7 +133,6 @@ SECTIONS
104133
KEEP(*(.init_array))
105134
PROVIDE_HIDDEN (__init_array_end = .);
106135

107-
108136
. = ALIGN(8);
109137
/* finit data */
110138
PROVIDE_HIDDEN (__fini_array_start = .);
@@ -120,20 +148,19 @@ SECTIONS
120148

121149
} > RAM
122150

123-
/* .stack section doesn't contains any symbols. It is only
124-
* used for linker to reserve space for the main stack section
125-
*/
126-
.stack (NOLOAD):
151+
/* Uninitialized data section
152+
* This region is not initialized by the C/C++ library and can be used to
153+
* store state across soft reboots. */
154+
.uninitialized (NOLOAD):
127155
{
128-
__StackLimit = .;
129-
*(.stack*);
130-
. += StackSize - (. - __StackLimit);
156+
. = ALIGN(32);
157+
__uninitialized_start = .;
158+
*(.uninitialized)
159+
KEEP(*(.keep.uninitialized))
160+
. = ALIGN(32);
161+
__uninitialized_end = .;
131162
} > RAM
132-
__StackTop = ADDR(.stack) + StackSize;
133-
_estack = __StackTop;
134-
__StackLimit = ADDR(.stack);
135-
PROVIDE(__stack = __StackTop);
136-
163+
137164
.bss :
138165
{
139166
. = ALIGN(8);
@@ -149,14 +176,27 @@ SECTIONS
149176
.heap (COPY):
150177
{
151178
__end__ = .;
152-
end = __end__;
153-
*(.heap*);
154-
. += (ORIGIN(RAM) + LENGTH(RAM) - .);
179+
PROVIDE(end = .);
180+
*(.heap*)
181+
. = ORIGIN(RAM) + LENGTH(RAM) - MBED_BOOT_STACK_SIZE;
155182
__HeapLimit = .;
156183
} > RAM
157184

158-
PROVIDE(__heap_size = SIZEOF(.heap));
159-
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
160-
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
185+
/* .stack_dummy section doesn't contains any symbols. It is only
186+
* used for linker to calculate size of stack sections, and assign
187+
* values to stack symbols later */
188+
.stack_dummy (COPY):
189+
{
190+
*(.stack*)
191+
} > RAM
192+
193+
/* Set stack top to end of RAM, and stack limit move down by
194+
* size of stack_dummy section */
195+
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
196+
_estack = __StackTop;
197+
__StackLimit = __StackTop - MBED_BOOT_STACK_SIZE;
198+
PROVIDE(__stack = __StackTop);
161199

200+
/* Check if data + heap + stack exceeds RAM limit */
201+
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
162202
}

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/TOOLCHAIN_IAR/stm32f070xb.icf

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
1-
/*###ICF### Section handled by ICF editor, don't touch! ****/
2-
/*-Editor annotation file-*/
3-
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
4-
/*-Specials-*/
5-
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
6-
/*-Memory Regions-*/
7-
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
8-
define symbol __ICFEDIT_region_ROM_end__ = 0x0801FFFF;
9-
define symbol __ICFEDIT_region_RAM_start__ = 0x200000C0;
10-
define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF;
11-
/*-Sizes-*/
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;
28+
}
29+
30+
if (!isdefinedsymbol(MBED_APP_SIZE)) {
31+
define symbol MBED_APP_SIZE = MBED_ROM_SIZE;
32+
}
33+
1234
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 */
1337
define symbol MBED_BOOT_STACK_SIZE = 0x400;
1438
}
15-
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
16-
define symbol __ICFEDIT_size_heap__ = 0xC00;
17-
/**** End of ICF editor section. ###ICF###*/
39+
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

1945
define memory mem with size = 4G;
20-
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
21-
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_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];
2248

23-
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
24-
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
49+
define block CSTACK with alignment = 8, size = MBED_BOOT_STACK_SIZE { };
50+
define block HEAP with alignment = 8, size = HEAP_SIZE { };
2551

2652
initialize by copy { readwrite };
2753
do not initialize { section .noinit };
2854

29-
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
55+
place at address mem: MBED_APP_START { readonly section .intvec };
3056

3157
place in ROM_region { readonly };
3258
place in RAM_region { readwrite,
3359
block CSTACK, block HEAP };
34-
35-
export symbol __ICFEDIT_region_RAM_start__;
36-
export symbol __ICFEDIT_region_RAM_end__;

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/cmsis_nvic.h

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
/* mbed Microcontroller Library
2-
* CMSIS-style functionality to support dynamic vectors
3-
*******************************************************************************
4-
* Copyright (c) 2015, STMicroelectronics
5-
* All rights reserved.
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
******************************************************************************
4+
* @attention
65
*
7-
* Redistribution and use in source and binary forms, with or without
8-
* modification, are permitted provided that the following conditions are met:
6+
* <h2><center>&copy; Copyright (c) 2015-2020 STMicroelectronics.
7+
* All rights reserved.</center></h2>
98
*
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.
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
1813
*
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-
*******************************************************************************
30-
*/
14+
******************************************************************************
15+
*/
3116

3217
#ifndef MBED_CMSIS_NVIC_H
3318
#define MBED_CMSIS_NVIC_H

0 commit comments

Comments
 (0)