Skip to content

Commit f15dbf2

Browse files
author
Cruz Monrreal
authored
Merge pull request #7706 from jamesbeyond/fm_mem
Refactoring memory regions definitions for Fast Models MPS2 targets
2 parents 8e25d2d + f2aae22 commit f15dbf2

File tree

34 files changed

+584
-511
lines changed

34 files changed

+584
-511
lines changed

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0/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_M0/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 26 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,14 @@
3434
; CMSDK_CM0 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
@@ -115,14 +91,14 @@ __Vectors DCD __initial_sp ; Top of Stack
11591
DCD UARTTX4_Handler ; UART 4 TX Handler
11692
DCD ADCSPI_Handler ; SHIELD ADC SPI exceptions Handler
11793
DCD SHIELDSPI_Handler ; SHIELD SPI exceptions Handler
118-
DCD PORT0_0_Handler ; GPIO Port 0 pin 0 Handler
119-
DCD PORT0_1_Handler ; GPIO Port 0 pin 1 Handler
120-
DCD PORT0_2_Handler ; GPIO Port 0 pin 2 Handler
121-
DCD PORT0_3_Handler ; GPIO Port 0 pin 3 Handler
122-
DCD PORT0_4_Handler ; GPIO Port 0 pin 4 Handler
123-
DCD PORT0_5_Handler ; GPIO Port 0 pin 5 Handler
124-
DCD PORT0_6_Handler ; GPIO Port 0 pin 6 Handler
125-
DCD PORT0_7_Handler ; GPIO Port 0 pin 7 Handler
94+
DCD PORT0_0_Handler ; GPIO Port 0 pin 0 Handler
95+
DCD PORT0_1_Handler ; GPIO Port 0 pin 1 Handler
96+
DCD PORT0_2_Handler ; GPIO Port 0 pin 2 Handler
97+
DCD PORT0_3_Handler ; GPIO Port 0 pin 3 Handler
98+
DCD PORT0_4_Handler ; GPIO Port 0 pin 4 Handler
99+
DCD PORT0_5_Handler ; GPIO Port 0 pin 5 Handler
100+
DCD PORT0_6_Handler ; GPIO Port 0 pin 6 Handler
101+
DCD PORT0_7_Handler ; GPIO Port 0 pin 7 Handler
126102
__Vectors_End
127103

128104
__Vectors_Size EQU __Vectors_End - __Vectors
@@ -217,54 +193,27 @@ UARTOVF_Handler
217193
ETHERNET_Handler
218194
I2S_Handler
219195
TSC_Handler
220-
PORT2_COMB_Handler
221-
PORT3_COMB_Handler
222-
UARTRX3_Handler
223-
UARTTX3_Handler
224-
UARTRX4_Handler
225-
UARTTX4_Handler
226-
ADCSPI_Handler
227-
SHIELDSPI_Handler
228-
PORT0_0_Handler
229-
PORT0_1_Handler
230-
PORT0_2_Handler
231-
PORT0_3_Handler
232-
PORT0_4_Handler
233-
PORT0_5_Handler
234-
PORT0_6_Handler
235-
PORT0_7_Handler
196+
PORT2_COMB_Handler
197+
PORT3_COMB_Handler
198+
UARTRX3_Handler
199+
UARTTX3_Handler
200+
UARTRX4_Handler
201+
UARTTX4_Handler
202+
ADCSPI_Handler
203+
SHIELDSPI_Handler
204+
PORT0_0_Handler
205+
PORT0_1_Handler
206+
PORT0_2_Handler
207+
PORT0_3_Handler
208+
PORT0_4_Handler
209+
PORT0_5_Handler
210+
PORT0_6_Handler
211+
PORT0_7_Handler
236212
B .
237213

238214
ENDP
239215

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_M0/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 = 0x100;
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_M0/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_M0/device/cmsis_nvic.c

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,20 @@
2828
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2929
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3030
* POSSIBILITY OF SUCH DAMAGE.
31-
*******************************************************************************
32-
* CMSIS-style functionality to support dynamic vectors
3331
*******************************************************************************/
3432

33+
3534
#ifndef MBED_CMSIS_NVIC_H
3635
#define MBED_CMSIS_NVIC_H
3736

38-
#include "cmsis.h"
39-
40-
#define NVIC_NUM_VECTORS (16 + 48)
41-
#define NVIC_USER_IRQ_OFFSET 16
37+
#include "memory_zones.h"
4238

43-
#ifdef __cplusplus
44-
extern "C" {
45-
#endif
39+
#define NVIC_NUM_VECTORS (16 + 48)
40+
#define NVIC_RAM_VECTOR_ADDRESS ZBT_SRAM2_START // Location of vectors in RAM
4641

47-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
48-
uint32_t NVIC_GetVector(IRQn_Type IRQn);
49-
50-
#ifdef __cplusplus
51-
}
52-
#endif
42+
/*
43+
* Size of the whole vector table in bytes. Each vector is on 32 bits.
44+
*/
45+
#define NVIC_VECTORS_SIZE (NVIC_NUM_VECTORS * 4)
5346

5447
#endif

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/memory_zones.h renamed to targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0/device/memory_zones.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232

3333
/*
3434
* Code memory zones
35-
* Please note that MPS2 on Fast Models do not simulate persistent flash memory.
36-
* The FLASH memory zone is a 256 KiB SRAM block and named FLASH
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
3737
* only to keep the same name than in the CMSDK RTL and Fast Models Reference
3838
* Guide.
3939
*/
40-
#define FLASH_START 0x00000000
41-
#define FLASH_SIZE 0x00040000 /* 256 KiB */
42-
#define ZBT_SRAM1_START 0x00400000
43-
#define ZBT_SRAM1_SIZE 0x00400000 /* 4 MiB */
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*/
4444

4545
/* Data memory zones */
4646
#define ZBT_SRAM2_START 0x20000000
47-
#define ZBT_SRAM2_SIZE 0x00800000 /* 8 MiB */
47+
#define ZBT_SRAM2_SIZE 0x00400000 /* 4 MiB */
4848

4949
#endif /* MEMORY_ZONES_H */
5050

0 commit comments

Comments
 (0)