Skip to content

Commit 7b325f3

Browse files
authored
Merge pull request #6168 from hug-dev/cm3ds-memory
CM3DS Maintenance Pull Request: Memory changes (2/4)
2 parents 7125c8a + 5a68dcd commit 7b325f3

File tree

9 files changed

+232
-52
lines changed

9 files changed

+232
-52
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Cortex-M3 Design Start Eval package example on MPS2+ board
2+
3+
This folder includes the port of Mbed OS on the example system of the Cortex-M3
4+
Design Start Eval package. This example is implemented in FPGA on the MPS2+
5+
board. Please see this target's [Mbed page](https://os.mbed.com/platforms/ARM-CM3DS/)
6+
for more information.
7+
For convenience, this target is called **CM3DS**.
8+
9+
## Compiling
10+
11+
The target name is `ARM_CM3DS_MPS2`. You can compile Mbed OS
12+
projects for CM3DS with:
13+
14+
```bash
15+
mbed compile -t COMPILER -m ARM_CM3DS_MPS2
16+
```
17+
18+
Mbed OS supports the following compilers (replace `COMPILER` with):
19+
20+
* `ARM` for Arm Compiler version 5.
21+
* `GCC_ARM` for GNU Compiler for Arm.
22+
* `IAR` for IAR compiler.
23+
24+
## Running
25+
26+
Because of the new memory configuration introduced in commit `CM3DS: switch to
27+
larger memories for code and data`, it
28+
has become easier (and portable among all compilers) to use `.elf` files
29+
instead of `.bin`. `.elf` files are now the default for CM3DS projects, and compilation
30+
generates only them.
31+
For `.elf` files to work, you need **at least version 2.2.5** of the MPS2+
32+
firmware. For more information, please see the [firmware version 2.2.6 and instructions on how to put it
33+
in the MPS2+ board](https://community.arm.com/processors/designstart/f/discussions/9727/mps2-firmware-for-mbed).
34+
35+
## Testing
36+
37+
If you want to execute the Mbed OS greentea tests on CM3DS, you need
38+
**at least firmware version 2.2.6**.
39+
40+
* `mbedls` does not automatically recognize which serial port is linked to the
41+
board. Check it manually, and create a file named `mbedls.json` containing
42+
(at the same level than where you execute all commands):
43+
44+
```bash
45+
{
46+
"50040200074D652F3828F333": {
47+
"serial_port": "/dev/ttyUSB0"
48+
}
49+
}
50+
```
51+
52+
Replace `/dev/ttyUSB0` with your correct serial port
53+
(something like `COM6` on Windows).
54+
55+
* `mbedls` does not link CM3DS target ID with its name, so execute the command:
56+
57+
```bash
58+
mbedls --mock 5004:ARM_CM3DS_MPS2
59+
```
60+
61+
* You can now compile and run the tests:
62+
63+
```bash
64+
mbed test -m ARM_CM3DS_MPS2 -t COMPILER
65+
```

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/TOOLCHAIN_ARM_STD/MPS2.sct

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#! armcc -E
2+
13
/*
24
* MPS2 CMSIS Library
35
*
4-
* Copyright (c) 2006-2017 ARM Limited. All rights reserved.
6+
* Copyright (c) 2006-2018 ARM Limited. All rights reserved.
57
*
68
* SPDX-License-Identifier: Apache-2.0
79
*
@@ -22,16 +24,25 @@
2224
*************************************************************
2325
*/
2426

25-
LR_IROM1 0x00000000 0x00040000 { ; load region size_region
26-
ER_IROM1 0x00000000 0x00040000 { ; load address = execution address
27+
#include "../memory_zones.h"
28+
#include "../cmsis_nvic.h"
29+
30+
; The vector table is loaded at address 0x00000000 in Flash memory region.
31+
LR_IROM1 FLASH_START FLASH_SIZE {
32+
ER_IROM1 FLASH_START FLASH_SIZE {
2733
*.o (RESET, +First)
34+
}
35+
}
36+
37+
; Rest of the code is loaded to the ZBT SSRAM1.
38+
LR_IROM2 ZBT_SSRAM1_START ZBT_SSRAM1_SIZE {
39+
ER_IROM2 ZBT_SSRAM1_START ZBT_SSRAM1_SIZE {
2840
*(InRoot$$Sections)
2941
.ANY (+RO)
3042
}
31-
; Total: 80 vectors = 320 bytes (0x140) to be reserved in RAM
32-
; This is a bit more than is necessary based on the number of
33-
; exception handlers.
34-
RW_IRAM1 (0x20000000+0x140) (0x20000-0x140) { ; RW data
43+
; At execution, RAM is set to be in ZBT SSRAM2 and 3, just after the vector
44+
; table previously moved from Flash.
45+
RW_IRAM1 (ZBT_SSRAM23_START + NVIC_VECTORS_SIZE) (ZBT_SSRAM23_SIZE - NVIC_VECTORS_SIZE) {
3546
.ANY (+RW +ZI)
3647
}
3748
}

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MPS2 CMSIS Library
33
*
4-
* Copyright (c) 2009-2017 ARM Limited. All rights reserved.
4+
* Copyright (c) 2009-2018 ARM Limited. All rights reserved.
55
*
66
* SPDX-License-Identifier: Apache-2.0
77
*
@@ -20,11 +20,11 @@
2020
*
2121
* This file is derivative of CMSIS V5.00 startup_ARMCM3.s
2222
*
23-
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
2423
*/
2524

25+
#include "memory_zones.h"
2626

27-
__initial_sp EQU 0x20020000 ; Top of RAM
27+
__initial_sp EQU ZBT_SSRAM23_START + ZBT_SSRAM23_SIZE ; Top of ZBT SSRAM2 and 3, used for data
2828

2929
PRESERVE8
3030
THUMB

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/TOOLCHAIN_GCC_ARM/MPS2.ld

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/*
2-
* MPS2 CMSIS Library
3-
*/
4-
/*
5-
* Copyright (c) 2009-2017 ARM Limited. All rights reserved.
2+
* Copyright (c) 2009-2018 ARM Limited. All rights reserved.
63
*
74
* SPDX-License-Identifier: Apache-2.0
85
*
@@ -17,21 +14,20 @@
1714
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1815
* See the License for the specific language governing permissions and
1916
* limitations under the License.
20-
*/
21-
/*
17+
*
2218
* This file is derivative of CMSIS V5.00 gcc_arm.ld
19+
*
20+
* Linker script for mbed CM3DS on MPS2
2321
*/
24-
/* Linker script for mbed CM3DS on MPS2 */
2522

26-
/* Linker script to configure memory regions. */
27-
/* The length of the VECTORS region is a bit larger than
28-
* is necessary based on the number of exception handlers.
29-
*/
23+
#include "../memory_zones.h"
24+
#include "../cmsis_nvic.h"
25+
3026
MEMORY
3127
{
32-
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
33-
FLASH (rx) : ORIGIN = 0x00000400, LENGTH = 0x00040000 - 0x00000400
34-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
28+
VECTORS (rx) : ORIGIN = FLASH_START, LENGTH = FLASH_SIZE
29+
FLASH (rx) : ORIGIN = ZBT_SSRAM1_START, LENGTH = ZBT_SSRAM1_SIZE
30+
RAM (rwx) : ORIGIN = ZBT_SSRAM23_START, LENGTH = ZBT_SSRAM23_SIZE
3531
}
3632

3733
/* Linker script to place sections and symbol values. Should be used together
@@ -66,7 +62,7 @@ HEAP_SIZE = 0x4000;
6662
STACK_SIZE = 0x1000;
6763

6864
/* Size of the vector table in SRAM */
69-
M_VECTOR_RAM_SIZE = 0x140;
65+
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;
7066

7167
SECTIONS
7268
{

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/TOOLCHAIN_IAR/MPS2.icf

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/*
2-
* MPS2 CMSIS Library
3-
*/
4-
/*
5-
* Copyright (c) 2009-2017 ARM Limited. All rights reserved.
2+
* Copyright (c) 2009-2018 ARM Limited. All rights reserved.
63
*
74
* SPDX-License-Identifier: Apache-2.0
85
*
@@ -19,26 +16,49 @@
1916
* limitations under the License.
2017
*/
2118

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.
19+
/*
20+
* WARNING: these symbols are the same as the defines in ../memory_zones.h but
21+
* can not be included here. Please make sure that the two definitions match.
22+
*/
23+
/* Code memory zones */
24+
define symbol FLASH_START = 0x00000000;
25+
define symbol FLASH_SIZE = 0x00040000; /* 256 KiB */
26+
define symbol ZBT_SSRAM1_START = 0x00400000;
27+
define symbol ZBT_SSRAM1_SIZE = 0x00400000; /* 4 MiB */
28+
29+
/* Data memory zones */
30+
define symbol SRAM0_START = 0x20000000;
31+
define symbol SRAM0_SIZE = 0x00008000; /* 32 KiB */
32+
define symbol SRAM1_START = 0x20008000;
33+
define symbol SRAM1_SIZE = 0x00008000; /* 32 KiB */
34+
define symbol SRAM2_START = 0x20010000;
35+
define symbol SRAM2_SIZE = 0x00008000; /* 32 KiB */
36+
define symbol SRAM3_START = 0x20018000;
37+
define symbol SRAM3_SIZE = 0x00008000; /* 32 KiB */
38+
define symbol ZBT_SSRAM23_START = 0x20400000;
39+
define symbol ZBT_SSRAM23_SIZE = 0x00400000; /* 4 MiB */
40+
41+
/* NVIC vector numbers and size. */
42+
define symbol NVIC_NUM_VECTORS = 16 + 57;
43+
define symbol NVIC_VECTORS_SIZE = NVIC_NUM_VECTORS * 4;
44+
45+
/* Specials */
46+
define symbol __ICFEDIT_intvec_start__ = FLASH_START;
47+
48+
/* Memory Regions */
49+
define symbol __ICFEDIT_region_ROM_start__ = ZBT_SSRAM1_START;
50+
define symbol __ICFEDIT_region_ROM_end__ = ZBT_SSRAM1_START + ZBT_SSRAM1_SIZE - 1;
51+
/*
52+
* At execution, RAM is set to be in ZBT SSRAM2 and 3, just after the vector
53+
* table previously moved from Flash.
2654
*/
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" */
30-
/*-Specials-*/
31-
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
32-
/*-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;
37-
/*-Sizes-*/
55+
define symbol __ICFEDIT_region_RAM_start__ = ZBT_SSRAM23_START + NVIC_VECTORS_SIZE;
56+
define symbol __ICFEDIT_region_RAM_end__ = ZBT_SSRAM23_START + ZBT_SSRAM23_SIZE;
57+
58+
/* Sizes */
3859
/* Heap and Stack size */
39-
define symbol __ICFEDIT_size_heap__ = 0x4000;
60+
define symbol __ICFEDIT_size_heap__ = 0xF000;
4061
define symbol __ICFEDIT_size_cstack__ = 0x1000;
41-
/**** End of ICF editor section. ###ICF###*/
4262

4363
define memory mem with size = 4G;
4464
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/cmsis_nvic.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2015-2017 ARM Limited
2+
* Copyright (c) 2015-2018 ARM Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,12 +14,35 @@
1414
* limitations under the License.
1515
*
1616
* CMSIS-style functionality to support dynamic vectors
17+
*
18+
* This file is included in ARM and GCC_ARM linker scripts.
19+
*
20+
* WARNING: IAR does not include this file and re-define these values in
21+
* MPS2.icf file. Please make sure that the two files share the same values.
1722
*/
1823

24+
#include "memory_zones.h"
25+
1926
#ifndef MBED_CMSIS_NVIC_H
2027
#define MBED_CMSIS_NVIC_H
2128

22-
#define NVIC_NUM_VECTORS (16 + 48)
23-
#define NVIC_RAM_VECTOR_ADDRESS 0x20000000 /* Location of vectors in RAM */
29+
/*
30+
* 16 vectors for initial stack pointer and internal exceptions (defined in
31+
* Armv7-M ARM).
32+
* 57 vectors for external interrupts (defined in CM3DS Eval RTL and Testbench
33+
* User Guide).
34+
*/
35+
#define NVIC_NUM_VECTORS (16 + 57)
36+
37+
/*
38+
* Location of vectors in RAM, they are copied at boot from adress 0x00000000 to
39+
* that address.
40+
*/
41+
#define NVIC_RAM_VECTOR_ADDRESS ZBT_SSRAM23_START
42+
43+
/*
44+
* Size of the whole vector table in bytes. Each vector is on 32 bits.
45+
*/
46+
#define NVIC_VECTORS_SIZE (NVIC_NUM_VECTORS * 4)
2447

2548
#endif /* MBED_CMSIS_NVIC_H */
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 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+
* This file contains the information of memory zones for code and data on
17+
* CM3DS.
18+
* It is used in startup code and linker scripts of supported compilers (ARM and
19+
* GCC_ARM).
20+
*
21+
* WARNING: IAR does not include this file and re-define these values in
22+
* MPS2.icf file. Please make sure that the two files share the same values.
23+
*
24+
* These memory zones are defined in section 4.1.1 of CM3DS Eval RTL and
25+
* Testbench User Guide.
26+
*/
27+
28+
#ifndef MEMORY_ZONES_H
29+
#define MEMORY_ZONES_H
30+
31+
/*
32+
* Code memory zones
33+
* Please note that CM3DS on MPS2 does not contain any persistent flash memory.
34+
* The FLASH memory zone is a 256 KiB SRAM block in the FPGA and named FLASH
35+
* only to keep the same name than in the CM3DS Eval RTL and Testbench User
36+
* Guide.
37+
*/
38+
#define FLASH_START 0x00000000
39+
#define FLASH_SIZE 0x00040000 /* 256 KiB */
40+
#define ZBT_SSRAM1_START 0x00400000
41+
#define ZBT_SSRAM1_SIZE 0x00400000 /* 4 MiB */
42+
43+
/* Data memory zones */
44+
#define SRAM0_START 0x20000000
45+
#define SRAM0_SIZE 0x00008000 /* 32 KiB */
46+
#define SRAM1_START 0x20008000
47+
#define SRAM1_SIZE 0x00008000 /* 32 KiB */
48+
#define SRAM2_START 0x20010000
49+
#define SRAM2_SIZE 0x00008000 /* 32 KiB */
50+
#define SRAM3_START 0x20018000
51+
#define SRAM3_SIZE 0x00008000 /* 32 KiB */
52+
#define ZBT_SSRAM23_START 0x20400000
53+
#define ZBT_SSRAM23_SIZE 0x00400000 /* 4 MiB */
54+
55+
#endif /* MEMORY_ZONES_H */
56+

targets/TARGET_ARM_SSG/mbed_rtx.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2016-2017 ARM Limited
2+
* Copyright (c) 2016-2018 ARM Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,12 +17,20 @@
1717
#ifndef MBED_MBED_RTX_H
1818
#define MBED_MBED_RTX_H
1919

20-
#if defined(TARGET_BEETLE) || defined(TARGET_CM3DS_MPS2)
20+
#if defined(TARGET_BEETLE)
2121

2222
#ifndef INITIAL_SP
2323
#define INITIAL_SP (0x20020000UL)
2424
#endif
2525

26+
#elif defined(TARGET_CM3DS_MPS2)
27+
28+
#include "memory_zones.h"
29+
30+
#ifndef INITIAL_SP
31+
#define INITIAL_SP (ZBT_SSRAM23_START + ZBT_SSRAM23_SIZE)
2632
#endif
2733

28-
#endif // MBED_MBED_RTX_H
34+
#endif /* defined(TARGET_...) */
35+
36+
#endif /* MBED_MBED_RTX_H */

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,7 @@
26642664
"core": "Cortex-M3",
26652665
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
26662666
"extra_labels": ["ARM_SSG", "CM3DS_MPS2"],
2667+
"OUTPUT_EXT": "elf",
26672668
"macros": ["CMSDK_CM3DS"],
26682669
"device_has": ["ANALOGIN", "ETHERNET", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI", "RTC", "LOWPOWERTIMER"],
26692670
"release_versions": ["2", "5"],

0 commit comments

Comments
 (0)