Skip to content

Commit a453faa

Browse files
committed
CM3DS: switch to larger memories for code and data
This patch changes the linker files and defines to use the ZBT SSRAM instead of the FPGA Block RAM for code and data. The section 4.1.1, Code and RAM memory map, of the CM3DS Eval RTL and testbench user guide explains the available memories. This switch improves code memory from 256 kB to 4 MB and data memory from 128 kB to 4 MB. However, the ZBT SSRAM1 for code memory begins at 0x00400000 while the processor can only boot at address 0x00000000 which means that it expects the vector table to be at that address. That is why we have to create 2 load regions in the linker scripts: one with only the vector table at address 0x0 and one with code + data at address 0x00400000. Because of these two load regions, linker will produce different behaviours: * GCC_ARM and IAR will only create 1 binary with both load regions padding with 0 in between. The binary will then be very large (at least 4 MB) and the flash process will take longer. * ARM and ARMC6 will create 2 binaries for the two load regions. The load addresses of the two binaries can be written in the images.txt file on the MPS2 board. You can also use the --bincombined option of fromelf utility to produce only 1 large binary. This patch also adds the memory_zones.h file to try to put in common all the memory addresses that were previously hard coded in the linker scripts / startup files. With that patch in, the simplest option is to directly use the .elf file with the MPS2, which is only possible with mbb_v225.ebf and more recent firmwares. It will now be the default for CM3DS. This commit works with greentea thanks to the now merged pull request ARMmbed/htrun#181 in order to copy .elf file to the MPS2 board. Signed-off-by: Hugues de Valon <[email protected]>
1 parent f67fe4a commit a453faa

File tree

9 files changed

+229
-52
lines changed

9 files changed

+229
-52
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 check the [mbed page](https://os.mbed.com/platforms/ARM-CM3DS/) of
6+
this target for more information.
7+
For convenience, this target is called **CM3DS**.
8+
9+
## Compiling :construction_worker:
10+
11+
The target name is `ARM_CM3DS_MPS2`, you should be able to compile mbed OS
12+
projects for CM3DS with:
13+
14+
```bash
15+
mbed compile -t COMPILER -m ARM_CM3DS_MPS2
16+
```
17+
18+
The following compilers are supported (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 :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 more easy (and portable amoung all compilers) to use `.elf` files
29+
instead of `.bin`. `.elf` files are now the default for CM3DS projects and only
30+
they will be generated out of the compilation.
31+
For `.elf` files to work, you will need **at least version 2.2.5** of the MPS2+
32+
firmware. You can find firmware version 2.2.6 and instructions on how to put it
33+
in the MPS2+ board [here](https://community.arm.com/processors/designstart/f/discussions/9727/mps2-firmware-for-mbed).
34+
35+
## Testing :zap:
36+
37+
If you want to execute the mbed OS greentea tests on CM3DS, you will 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+
```bash
44+
{
45+
"50040200074D652F3828F333": {
46+
"serial_port": "/dev/ttyUSB0"
47+
}
48+
}
49+
```
50+
Replace `/dev/ttyUSB0` with your correct serial port
51+
(something like `COM6` on Windows).
52+
53+
* `mbedls` does not link CM3DS target ID with its name so execute the command:
54+
```bash
55+
mbedls --mock 5004:ARM_CM3DS_MPS2
56+
```
57+
58+
* You can now compile and run the tests :+1: :
59+
```bash
60+
mbed test -m ARM_CM3DS_MPS2 -t COMPILER
61+
```
62+

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
@@ -2663,6 +2663,7 @@
26632663
"core": "Cortex-M3",
26642664
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
26652665
"extra_labels": ["ARM_SSG", "CM3DS_MPS2"],
2666+
"OUTPUT_EXT": "elf",
26662667
"macros": ["CMSDK_CM3DS"],
26672668
"device_has": ["ANALOGIN", "ETHERNET", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI", "RTC", "LOWPOWERTIMER"],
26682669
"release_versions": ["2", "5"],

0 commit comments

Comments
 (0)