Skip to content

Commit edcfcf0

Browse files
committed
M263: Enable configurability for memory specification
This is to support custom boards based on M261 series chips.
1 parent 203a9fe commit edcfcf0

File tree

6 files changed

+270
-31
lines changed

6 files changed

+270
-31
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 __M261_MEM_H__
20+
#define __M261_MEM_H__
21+
22+
/* About M261_mem.h/M261_mem.icf.h
23+
*
24+
* 1. M261_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 M261_mem.icf.h, duplicate of M261_mem.h
27+
* is created for IAR linker file.
28+
* 3. To continue above, we name M261_mem.icf.h instead of M261_mem.icf because:
29+
* (1) Mbed OS build tool may mis-regard M261_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 M261_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: 512KiB
39+
* SRAM size: 96KiB
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 (0x80000)
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 (0x18000)
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 /* __M261_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 M261_mem.h for documentation */
20+
21+
/* Default memory specification
22+
*
23+
* Flash size: 512KiB
24+
* SRAM size: 96KiB
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 = 0x80000;
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 = 0x18000;
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_M261/device/TOOLCHAIN_ARMC6/M261.sct

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,29 @@
1818
* limitations under the License.
1919
*/
2020

21-
22-
#if !defined(MBED_APP_START)
23-
#define MBED_APP_START 0x00000000
24-
#endif
25-
26-
#if !defined(MBED_APP_SIZE)
27-
#define MBED_APP_SIZE 0x00080000
28-
#endif
21+
#include "../M261_mem.h"
2922

3023
#if !defined(MBED_BOOT_STACK_SIZE)
3124
#define MBED_BOOT_STACK_SIZE 0x400
3225
#endif
3326

27+
#define VECTOR_SIZE (4*(16 + 102))
28+
3429
LR_IROM1 MBED_APP_START {
35-
ER_IROM1 MBED_APP_START { ; load address = execution address
30+
ER_IROM1 +0 { ; load address = execution address
3631
*(RESET, +First)
3732
*(InRoot$$Sections)
3833
.ANY (+RO)
3934
}
4035

41-
ARM_LIB_STACK 0x20000000 EMPTY MBED_BOOT_STACK_SIZE {
36+
ARM_LIB_STACK MBED_RAM_APP_START EMPTY MBED_BOOT_STACK_SIZE {
4237
}
4338

4439
/* Reserve for vectors
4540
*
4641
* Vector table base address is required to be 128-byte aligned at a minimum.
4742
* A PE might impose further restrictions on it. */
48-
ER_IRAMVEC AlignExpr(+0, 128) EMPTY (4*(16 + 102)) { ; Reserve for vectors
43+
ER_IRAMVEC AlignExpr(+0, 128) EMPTY VECTOR_SIZE { ; Reserve for vectors
4944
}
5045

5146
RW_m_crash_data AlignExpr(+0, 0x100) EMPTY 0x100 { ; Reserve for crash data storage
@@ -55,8 +50,8 @@ LR_IROM1 MBED_APP_START {
5550
.ANY (+RW +ZI)
5651
}
5752

58-
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x20000000 + 0x18000 - AlignExpr(ImageLimit(RW_IRAM1), 16)) {
53+
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_APP_START + MBED_RAM_APP_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) {
5954
}
6055
}
61-
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 512 KB APROM
62-
ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= 0x20018000) ; 96 KB SRAM
56+
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE))
57+
ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= (MBED_RAM_APP_START + MBED_RAM_APP_SIZE))

targets/TARGET_NUVOTON/TARGET_M261/device/TOOLCHAIN_GCC_ARM/M261.ld

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
* Nuvoton M261 GCC linker script file
2121
*/
2222

23-
#if !defined(MBED_APP_START)
24-
#define MBED_APP_START 0x00000000
25-
#endif
26-
27-
#if !defined(MBED_APP_SIZE)
28-
#define MBED_APP_SIZE 0x00080000
29-
#endif
23+
#include "../M261_mem.h"
3024

3125
#if !defined(MBED_BOOT_STACK_SIZE)
3226
#define MBED_BOOT_STACK_SIZE 0x400
@@ -39,7 +33,7 @@ MEMORY
3933
{
4034
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
4135
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x00000400
42-
RAM_INTERN (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00018000 - 0x00000000
36+
RAM_INTERN (rwx) : ORIGIN = MBED_RAM_APP_START, LENGTH = MBED_RAM_APP_SIZE
4337
}
4438

4539
/**

targets/TARGET_NUVOTON/TARGET_M261/device/TOOLCHAIN_IAR/M261.icf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919
/*###ICF### Section handled by ICF editor, don't touch! ****/
2020
/*-Editor annotation file-*/
2121
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
22-
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x00000000; }
23-
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x00080000; }
22+
23+
include "../M261_mem.icf.h";
24+
2425
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) { define symbol MBED_BOOT_STACK_SIZE = 0x400; }
2526
/*-Specials-*/
2627
define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
2728
/*-Memory Regions-*/
2829
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
2930
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
30-
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
31-
define symbol __ICFEDIT_region_IRAM_end__ = 0x20017F00 - 1;
32-
define symbol __region_CRASH_DATA_RAM_start__ = 0x20017F00;
33-
define symbol __region_CRASH_DATA_RAM_end__ = 0x20018000 - 1;
31+
define symbol __ICFEDIT_region_IRAM_start__ = MBED_RAM_APP_START;
32+
define symbol __ICFEDIT_region_IRAM_end__ = MBED_RAM_APP_START + MBED_RAM_APP_SIZE - 0x100 - 1;
33+
define symbol __region_CRASH_DATA_RAM_start__ = MBED_RAM_APP_START + MBED_RAM_APP_SIZE - 0x100;
34+
define symbol __region_CRASH_DATA_RAM_end__ = MBED_RAM_APP_START + MBED_RAM_APP_SIZE - 1;
3435
/*-Sizes-*/
3536
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
3637
define symbol __ICFEDIT_size_intvec__ = (4 * (16 + 102));

targets/TARGET_NUVOTON/TARGET_M261/flash_api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string.h>
2323
#include "flash_data.h"
2424
#include "mbed_critical.h"
25+
#include "M261_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.
@@ -82,16 +83,16 @@ static const flash_algo_t flash_algo_config = {
8283
};
8384

8485
static const sector_info_t sectors_info[] = {
85-
{0x0, 0x800}, // (start, sector size)
86+
{MBED_ROM_START, 0x800}, // (start, sector size)
8687
};
8788

8889
/* Secure flash */
8990
static const flash_target_config_t flash_target_config = {
9091
.page_size = 4, // 4 bytes
9192
// Here page_size is program unit, which is different
9293
// than FMC definition.
93-
.flash_start = 0x0,
94-
.flash_size = 0x80000, // 512 KB
94+
.flash_start = MBED_ROM_START,
95+
.flash_size = MBED_ROM_SIZE,
9596
.sectors = sectors_info,
9697
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
9798
};

0 commit comments

Comments
 (0)