Skip to content

Commit 6f92504

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
Refactoring memory regions definitions for MPS2_M0P targets
* added memory_zones.h * all linker scripts reference the definitions from memory_zones.h * tool chains use predefined 1K as ISR Stack size * ARM Complier 5 and GCC will auto calculated heap size * IAR use predefined 2MiB as heap size
1 parent 8fc3842 commit 6f92504

File tree

6 files changed

+119
-81
lines changed

6 files changed

+119
-81
lines changed

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_ARM_STD/MPS2.sct

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! armcc -E
12
;* MPS2 CMSIS Library
23
;*
34
;* Copyright (c) 2006-2018 ARM Limited
@@ -33,15 +34,31 @@
3334
; *** Scatter-Loading Description File ***
3435
; *************************************************************
3536

36-
LR_IROM1 0x00000000 0x00400000 { ; load region size_region
37-
ER_IROM1 0x00000000 0x00400000 { ; load address = execution address
37+
#include "../memory_zones.h"
38+
#include "../cmsis_nvic.h"
39+
40+
#if (defined(__stack_size__))
41+
#define STACK_SIZE __stack_size__
42+
#else
43+
#define STACK_SIZE 0x0400
44+
#endif
45+
46+
; The vector table is loaded at address 0x00000000 in Flash memory region.
47+
LR_IROM1 MAPPABLE_START MAPPABLE_SIZE {
48+
ER_IROM1 MAPPABLE_START MAPPABLE_SIZE {
3849
*.o (RESET, +First)
50+
}
51+
}
52+
53+
LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
54+
ER_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load address = execution address
3955
*(InRoot$$Sections)
4056
.ANY (+RO)
4157
}
42-
; Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
43-
RW_IRAM1 (0x20000000+0x100) (0x400000-0x100) { ; RW data
58+
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
59+
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
4460
.ANY (+RW +ZI)
4561
}
62+
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down
63+
}
4664
}
47-

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,14 @@
3434
; CMSDK_CM0P Device
3535
;
3636
;******************************************************************************
37-
;
38-
;-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
39-
;
40-
41-
42-
; <h> Stack Configuration
43-
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
44-
; </h>
45-
46-
Stack_Size EQU 0x00004000
47-
48-
AREA STACK, NOINIT, READWRITE, ALIGN=3
49-
Stack_Mem SPACE Stack_Size
50-
__initial_sp
5137

38+
#include "../memory_zones.h"
5239

53-
; <h> Heap Configuration
54-
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
55-
; </h>
56-
57-
Heap_Size EQU 0x00001000
58-
59-
AREA HEAP, NOINIT, READWRITE, ALIGN=3
60-
__heap_base
61-
Heap_Mem SPACE Heap_Size
62-
__heap_limit
63-
40+
__initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
6441

6542
PRESERVE8
6643
THUMB
6744

68-
6945
; Vector Table Mapped to Address 0 at Reset
7046

7147
AREA RESET, DATA, READONLY
@@ -240,31 +216,4 @@ PORT0_7_Handler
240216

241217
ALIGN
242218

243-
244-
; User Initial Stack & Heap
245-
246-
IF :DEF:__MICROLIB
247-
248-
EXPORT __initial_sp
249-
EXPORT __heap_base
250-
EXPORT __heap_limit
251-
252-
ELSE
253-
254-
IMPORT __use_two_region_memory
255-
EXPORT __user_initial_stackheap
256-
257-
__user_initial_stackheap PROC
258-
LDR R0, = Heap_Mem
259-
LDR R1, =(Stack_Mem + Stack_Size)
260-
LDR R2, = (Heap_Mem + Heap_Size)
261-
LDR R3, = Stack_Mem
262-
BX LR
263-
ENDP
264-
265-
ALIGN
266-
267-
ENDIF
268-
269-
270219
END

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_GCC_ARM/MPS2.ld

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@
2727
/* The length of the VECTORS region is a bit larger than
2828
* is necessary based on the number of exception handlers.
2929
*/
30+
31+
#include "../memory_zones.h"
32+
#include "../cmsis_nvic.h"
33+
3034
MEMORY
3135
{
32-
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
33-
FLASH (rx) : ORIGIN = 0x00000400, LENGTH = 0x00040000 - 0x00000400
34-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
36+
VECTORS (rx) : ORIGIN = MAPPABLE_START, LENGTH = MAPPABLE_SIZE
37+
FLASH (rx) : ORIGIN = ZBT_SRAM1_START, LENGTH = ZBT_SRAM1_SIZE
38+
RAM (rwx) : ORIGIN = ZBT_SRAM2_START, LENGTH = ZBT_SRAM2_SIZE
3539
}
3640

3741
/* Linker script to place sections and symbol values. Should be used together
@@ -62,11 +66,10 @@ MEMORY
6266
*/
6367
ENTRY(Reset_Handler)
6468

65-
HEAP_SIZE = 0x4000;
66-
STACK_SIZE = 0x1000;
69+
STACK_SIZE = 0x400;
6770

6871
/* Size of the vector table in SRAM */
69-
M_VECTOR_RAM_SIZE = 0x140;
72+
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;
7073

7174
SECTIONS
7275
{
@@ -188,13 +191,13 @@ SECTIONS
188191

189192
bss_size = __bss_end__ - __bss_start__;
190193

191-
.heap :
194+
.heap (COPY):
192195
{
193196
. = ALIGN(8);
194197
__end__ = .;
195198
PROVIDE(end = .);
196199
__HeapBase = .;
197-
. += HEAP_SIZE;
200+
*(.heap*)
198201
__HeapLimit = .;
199202
__heap_limit = .; /* Add for _sbrk */
200203
} > RAM

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_IAR/MPS2.icf

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,37 @@
1919
* limitations under the License.
2020
*/
2121

22-
/* The RAM region doesn't start at the beginning of the RAM address
23-
* space to create space for the vector table copied over to the RAM by mbed.
24-
* The space left is a bit bigger than is necessary based on the number of
25-
* interrupt handlers.
22+
/*
23+
* WARNING: these symbols are the same as the defines in ../memory_zones.h but
24+
* can not be included here. Please make sure that the two definitions match.
2625
*/
27-
/*###ICF### Section handled by ICF editor, don't touch! ****/
28-
/*-Editor annotation file-*/
29-
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
26+
/* Code memory zones */
27+
define symbol MAPPABLE_START = 0x00000000;
28+
define symbol MAPPABLE_SIZE = 0x00004000; /* 16 KiB */
29+
define symbol ZBT_SRAM1_START = (0x00000000 + 0x00004000);
30+
define symbol ZBT_SRAM1_SIZE = (0x00400000 - 0x00004000); /* 4 MiB - 16 KiB */
31+
32+
/* Data memory zones */
33+
define symbol ZBT_SRAM2_START = 0x20000000;
34+
define symbol ZBT_SRAM2_SIZE = 0x00400000; /* 4 MB */
35+
36+
/* NVIC vector numbers and size. */
37+
define symbol NVIC_NUM_VECTORS = (16 + 48);
38+
define symbol NVIC_VECTORS_SIZE = (NVIC_NUM_VECTORS * 4);
39+
3040
/*-Specials-*/
31-
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
41+
define symbol __ICFEDIT_intvec_start__ = MAPPABLE_START;
42+
3243
/*-Memory Regions-*/
33-
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
34-
define symbol __ICFEDIT_region_ROM_end__ = 0x0003FFFF;
35-
define symbol __ICFEDIT_region_RAM_start__ = 0x20000140;
36-
define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF;
44+
define symbol __ICFEDIT_region_ROM_start__ = ZBT_SRAM1_START;
45+
define symbol __ICFEDIT_region_ROM_end__ = ZBT_SRAM1_START + ZBT_SRAM1_SIZE - 1;
46+
define symbol __ICFEDIT_region_RAM_start__ = ZBT_SRAM2_START + NVIC_VECTORS_SIZE;
47+
define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE - 1;
48+
3749
/*-Sizes-*/
3850
/* Heap and Stack size */
39-
define symbol __ICFEDIT_size_heap__ = 0x4000;
40-
define symbol __ICFEDIT_size_cstack__ = 0x1000;
51+
define symbol __ICFEDIT_size_heap__ = 0x200000;
52+
define symbol __ICFEDIT_size_cstack__ = 0x400;
4153
/**** End of ICF editor section. ###ICF###*/
4254

4355
define memory mem with size = 4G;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/cmsis_nvic.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333
#ifndef MBED_CMSIS_NVIC_H
3434
#define MBED_CMSIS_NVIC_H
3535

36+
#include "memory_zones.h"
37+
3638
#define NVIC_NUM_VECTORS (16 + 48)
37-
#define NVIC_RAM_VECTOR_ADDRESS 0x20000000 // Location of vectors in RAM
39+
#define NVIC_RAM_VECTOR_ADDRESS ZBT_SRAM2_START // Location of vectors in RAM
40+
41+
/*
42+
* Size of the whole vector table in bytes. Each vector is on 32 bits.
43+
*/
44+
#define NVIC_VECTORS_SIZE (NVIC_NUM_VECTORS * 4)
3845

3946
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2017-2018 ARM Limited
3+
*
4+
* Licensed under the Apache License Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing software
11+
* distributed under the License is distributed on an "AS IS" BASIS
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* This file contains the information of memory zones for code and data on
19+
* ARM Versatile Express Cortex-M Prototyping Systems (V2M-MPS2) TRM.
20+
* It is used in startup code and linker scripts of supported compilers (ARM and
21+
* GCC_ARM).
22+
*
23+
* WARNING: IAR does not include this file and re-define these values in
24+
* MPS2.icf file. Please make sure that the two files share the same values.
25+
*
26+
* These memory zones are defined in section 4.2 of ARM V2M-MPS2 RTL and
27+
* Fast Model Reference Guide.
28+
*/
29+
30+
#ifndef MEMORY_ZONES_H
31+
#define MEMORY_ZONES_H
32+
33+
/*
34+
* Code memory zones
35+
* Please note that MPS2 on Fast Models do not implemented persistent flash memory.
36+
* The FLASH memory can be simulated via 4MB ZBT_SRAM1 block
37+
* only to keep the same name than in the CMSDK RTL and Fast Models Reference
38+
* Guide.
39+
*/
40+
#define MAPPABLE_START 0x00000000
41+
#define MAPPABLE_SIZE 0x00004000 /* 16 KiB */
42+
#define ZBT_SRAM1_START (0x00000000 + 0x00004000)
43+
#define ZBT_SRAM1_SIZE (0x00400000 - 0x00004000) /* 4 MiB - 16 KiB*/
44+
45+
/* Data memory zones */
46+
#define ZBT_SRAM2_START 0x20000000
47+
#define ZBT_SRAM2_SIZE 0x00400000 /* 4 MiB */
48+
49+
#endif /* MEMORY_ZONES_H */
50+

0 commit comments

Comments
 (0)