Skip to content

Commit f7e4a75

Browse files
committed
M252: Make memory specification configurable
This is to support all M251 series based targets.
1 parent 1f70a3c commit f7e4a75

File tree

6 files changed

+259
-51
lines changed

6 files changed

+259
-51
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2020, Nuvoton Technology Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef __M251_MEM_H__
20+
#define __M251_MEM_H__
21+
22+
/* About M251_mem.h/M251_mem.icf.h
23+
*
24+
* 1. M251_mem.h is created for centralizing memory configuration. It will be included by C/C++ files
25+
* and linker files (except IAR linker file).
26+
* 2. IAR linker doesn't support preprocessor, so M251_mem.icf.h, duplicate of M251_mem.h
27+
* is created for IAR linker file.
28+
* 3. To continue above, we name M251_mem.icf.h instead of M251_mem.icf because:
29+
* (1) Mbed OS build tool may mis-regard M251_mem.icf as the main linker configuration file.
30+
* (2) *.icf files may not be present in search directories for "include" directive. Per observation,
31+
* the search directories are inconsistent among normal example build and test code build. To address
32+
* it, we name M251_mem.icf.h instead because *.h files are always present in these builds
33+
* (already there or via copy).
34+
*/
35+
36+
/* Default memory specification
37+
*
38+
* Flash size: 256KiB
39+
* SRAM size: 32KiB
40+
*/
41+
42+
/* Resolve ROM start */
43+
#ifndef MBED_ROM_START
44+
#define MBED_ROM_START (0x0)
45+
#endif
46+
47+
/* Resolve ROM size */
48+
#ifndef MBED_ROM_SIZE
49+
#define MBED_ROM_SIZE (0x40000)
50+
#endif
51+
52+
/* Resolve RAM start */
53+
#ifndef MBED_RAM_START
54+
#define MBED_RAM_START (0x20000000)
55+
#endif
56+
57+
/* Resolve RAM size */
58+
#ifndef MBED_RAM_SIZE
59+
#define MBED_RAM_SIZE (0x8000)
60+
#endif
61+
62+
63+
/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
64+
* MBED_APP_xxx macros to linker files even though they mean the same thing.
65+
* Because this file is to include by both C/C++ files and linker files, we add
66+
* these macros according to the others for consistency when they are missing
67+
* in compile or link stage. */
68+
69+
#ifndef APPLICATION_ADDR
70+
#ifdef MBED_APP_START
71+
#define APPLICATION_ADDR MBED_APP_START
72+
#else
73+
#define APPLICATION_ADDR MBED_ROM_START
74+
#endif
75+
#endif
76+
77+
#ifndef APPLICATION_SIZE
78+
#ifdef MBED_APP_SIZE
79+
#define APPLICATION_SIZE MBED_APP_SIZE
80+
#else
81+
#define APPLICATION_SIZE MBED_ROM_SIZE
82+
#endif
83+
#endif
84+
85+
#ifndef APPLICATION_RAM_ADDR
86+
#ifdef MBED_RAM_APP_START
87+
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
88+
#else
89+
#define APPLICATION_RAM_ADDR MBED_RAM_START
90+
#endif
91+
#endif
92+
93+
#ifndef APPLICATION_RAM_SIZE
94+
#ifdef MBED_RAM_APP_SIZE
95+
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
96+
#else
97+
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
98+
#endif
99+
#endif
100+
101+
#ifndef MBED_APP_START
102+
#define MBED_APP_START APPLICATION_ADDR
103+
#endif
104+
105+
#ifndef MBED_APP_SIZE
106+
#define MBED_APP_SIZE APPLICATION_SIZE
107+
#endif
108+
109+
#ifndef MBED_RAM_APP_START
110+
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
111+
#endif
112+
113+
#ifndef MBED_RAM_APP_SIZE
114+
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
115+
#endif
116+
117+
#if (APPLICATION_ADDR != MBED_APP_START)
118+
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
119+
#endif
120+
121+
#if (APPLICATION_SIZE != MBED_APP_SIZE)
122+
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
123+
#endif
124+
125+
#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
126+
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
127+
#endif
128+
129+
#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
130+
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
131+
#endif
132+
133+
#endif /* __M251_MEM_H__ */
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (c) 2020, Nuvoton Technology Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* See M251_mem.h for documentation */
20+
21+
/* Default memory specification
22+
*
23+
* Flash size: 256KiB
24+
* SRAM size: 32KiB
25+
*/
26+
27+
/* Resolve ROM start */
28+
if (!isdefinedsymbol(MBED_ROM_START)) {
29+
define symbol MBED_ROM_START = 0x0;
30+
}
31+
32+
/* Resolve ROM size */
33+
if (!isdefinedsymbol(MBED_ROM_SIZE)) {
34+
define symbol MBED_ROM_SIZE = 0x40000;
35+
}
36+
37+
/* Resolve RAM start */
38+
if (!isdefinedsymbol(MBED_RAM_START)) {
39+
define symbol MBED_RAM_START = 0x20000000;
40+
}
41+
42+
/* Resolve RAM size */
43+
if (!isdefinedsymbol(MBED_RAM_SIZE)) {
44+
define symbol MBED_RAM_SIZE = 0x8000;
45+
}
46+
47+
/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
48+
* MBED_APP_xxx macros to linker files even though they mean the same thing.
49+
* Because this file is to include by both C/C++ files and linker files, we add
50+
* these macros according to the others for consistency when they are missing
51+
* in compile or link stage. */
52+
53+
if (!isdefinedsymbol(APPLICATION_ADDR)) {
54+
if (isdefinedsymbol(MBED_APP_START)) {
55+
define symbol APPLICATION_ADDR = MBED_APP_START;
56+
} else {
57+
define symbol APPLICATION_ADDR = MBED_ROM_START;
58+
}
59+
}
60+
61+
if (!isdefinedsymbol(APPLICATION_SIZE)) {
62+
if (isdefinedsymbol(MBED_APP_SIZE)) {
63+
define symbol APPLICATION_SIZE = MBED_APP_SIZE;
64+
} else {
65+
define symbol APPLICATION_SIZE = MBED_ROM_SIZE;
66+
}
67+
}
68+
69+
if (!isdefinedsymbol(APPLICATION_RAM_ADDR)) {
70+
if (isdefinedsymbol(MBED_RAM_APP_START)) {
71+
define symbol APPLICATION_RAM_ADDR = MBED_RAM_APP_START;
72+
} else {
73+
define symbol APPLICATION_RAM_ADDR = MBED_RAM_START;
74+
}
75+
}
76+
77+
if (!isdefinedsymbol(APPLICATION_RAM_SIZE)) {
78+
if (isdefinedsymbol(MBED_RAM_APP_SIZE)) {
79+
define symbol APPLICATION_RAM_SIZE = MBED_RAM_APP_SIZE;
80+
} else {
81+
define symbol APPLICATION_RAM_SIZE = MBED_RAM_SIZE;
82+
}
83+
}
84+
85+
if (!isdefinedsymbol(MBED_APP_START)) {
86+
define symbol MBED_APP_START = APPLICATION_ADDR;
87+
}
88+
89+
if (!isdefinedsymbol(MBED_APP_SIZE)) {
90+
define symbol MBED_APP_SIZE = APPLICATION_SIZE;
91+
}
92+
93+
if (!isdefinedsymbol(MBED_RAM_APP_START)) {
94+
define symbol MBED_RAM_APP_START = APPLICATION_RAM_ADDR;
95+
}
96+
97+
if (!isdefinedsymbol(MBED_RAM_APP_SIZE)) {
98+
define symbol MBED_RAM_APP_SIZE = APPLICATION_RAM_SIZE;
99+
}
100+
101+
if (APPLICATION_ADDR != MBED_APP_START) {
102+
error "APPLICATION_ADDR and MBED_APP_START are not the same!!!";
103+
}
104+
105+
if (APPLICATION_SIZE != MBED_APP_SIZE) {
106+
error "APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!";
107+
}
108+
109+
if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START) {
110+
error "APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!";
111+
}
112+
113+
if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE) {
114+
error "APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!";
115+
}

targets/TARGET_NUVOTON/TARGET_M251/device/TOOLCHAIN_ARMC6/M251.sct

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,15 @@
1818
* limitations under the License.
1919
*/
2020

21-
#if !defined(MBED_APP_START)
22-
#define MBED_APP_START 0x00000000
23-
#endif
24-
25-
#if !defined(MBED_APP_SIZE)
26-
#define MBED_APP_SIZE 0x00040000
27-
#endif
28-
29-
#if !defined(MBED_RAM_APP_START)
30-
#define MBED_RAM_APP_START 0x20000000
31-
#endif
32-
33-
#if !defined(MBED_RAM_APP_SIZE)
34-
#define MBED_RAM_APP_SIZE 0x8000
35-
#endif
21+
#include "../M251_mem.h"
3622

3723
#if !defined(MBED_BOOT_STACK_SIZE)
3824
#define MBED_BOOT_STACK_SIZE 0x400
3925
#endif
4026

41-
LR_IROM1 MBED_APP_START
27+
#define VECTOR_SIZE (4*(16 + 64))
28+
29+
LR_IROM1 MBED_APP_START MBED_APP_SIZE
4230
{
4331
/* load address = execution address */
4432
ER_IROM1 +0
@@ -56,7 +44,7 @@ LR_IROM1 MBED_APP_START
5644
*
5745
* Vector table base address is required to be 128-byte aligned at a minimum.
5846
* A PE might impose further restrictions on it. */
59-
ER_IRAMVEC AlignExpr(+0, 128) EMPTY (4*(16 + 64))
47+
ER_IRAMVEC AlignExpr(+0, 128) EMPTY VECTOR_SIZE
6048
{
6149
}
6250

targets/TARGET_NUVOTON/TARGET_M251/device/TOOLCHAIN_GCC_ARM/M251.ld

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,7 @@
1818

1919
/* Nuvoton M251 GCC linker script file */
2020

21-
#if !defined(MBED_APP_START)
22-
#define MBED_APP_START 0x00000000
23-
#endif
24-
25-
#if !defined(MBED_APP_SIZE)
26-
#define MBED_APP_SIZE 0x00040000
27-
#endif
28-
29-
#if !defined(MBED_RAM_APP_START)
30-
#define MBED_RAM_APP_START 0x20000000
31-
#endif
32-
33-
#if !defined(MBED_RAM_APP_SIZE)
34-
#define MBED_RAM_APP_SIZE 0x8000
35-
#endif
21+
#include "../M251_mem.h"
3622

3723
#if !defined(MBED_BOOT_STACK_SIZE)
3824
#define MBED_BOOT_STACK_SIZE 0x400

targets/TARGET_NUVOTON/TARGET_M251/device/TOOLCHAIN_IAR/M251.icf

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,7 @@
2020
/*-Editor annotation file-*/
2121
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
2222

23-
if (! isdefinedsymbol(MBED_APP_START)) {
24-
define symbol MBED_APP_START = 0x00000000;
25-
}
26-
27-
if (! isdefinedsymbol(MBED_APP_SIZE)) {
28-
define symbol MBED_APP_SIZE = 0x00040000;
29-
}
30-
31-
if (! isdefinedsymbol(MBED_RAM_APP_START)) {
32-
define symbol MBED_RAM_APP_START = 0x20000000;
33-
}
34-
35-
36-
if (! isdefinedsymbol(MBED_RAM_APP_SIZE)) {
37-
define symbol MBED_RAM_APP_SIZE = 0x8000;
38-
}
23+
include "../M251_mem.icf.h";
3924

4025
if (! isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
4126
define symbol MBED_BOOT_STACK_SIZE = 0x400;

targets/TARGET_NUVOTON/TARGET_M251/flash_api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "flash_data.h"
2424
#include "mbed_critical.h"
25+
#include "M251_mem.h"
2526

2627
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2728
// NOTE: On ARMv7-M/ARMv8-M, instruction fetches are always little-endian.
@@ -93,16 +94,16 @@ static const flash_algo_t flash_algo_config = {
9394

9495
/* Secure flash */
9596
static const sector_info_t sectors_info[] = {
96-
{0x0, 0x200}, // (start, sector size)
97+
{MBED_ROM_START, 0x200}, // (start, sector size)
9798
};
9899

99100
/* Secure flash */
100101
static const flash_target_config_t flash_target_config = {
101102
.page_size = 4, // 4 bytes
102103
// Here page_size is program unit, which is different
103104
// than FMC definition.
104-
.flash_start = 0x0,
105-
.flash_size = 0x40000,
105+
.flash_start = MBED_ROM_START,
106+
.flash_size = MBED_ROM_SIZE,
106107
.sectors = sectors_info,
107108
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
108109
};

0 commit comments

Comments
 (0)