Skip to content

Commit 427e8eb

Browse files
committed
M2351: Support custom board
1. Introduce MCU_M2351 target to be inheritable 2. Re-organize PinNames.h to be overridable 3. Enable configurability of USB/STDIO UART pins
1 parent 4fa9cca commit 427e8eb

File tree

4 files changed

+181
-88
lines changed

4 files changed

+181
-88
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/PeripheralNames.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define MBED_PERIPHERALNAMES_H
1919

2020
#include "cmsis.h"
21+
#include "PinNames.h"
2122
#include "partition_M2351.h"
2223

2324
#ifdef __cplusplus
@@ -181,7 +182,16 @@ typedef enum {
181182
#endif
182183

183184
// NOTE: board-specific
184-
STDIO_UART = UART_0,
185+
#if defined(MBED_CONF_TARGET_USB_UART)
186+
USB_UART = MBED_CONF_TARGET_USB_UART,
187+
#else
188+
USB_UART = NC,
189+
#endif
190+
#if defined(MBED_CONF_TARGET_STDIO_UART)
191+
STDIO_UART = MBED_CONF_TARGET_STDIO_UART,
192+
#else
193+
STDIO_UART = USB_UART,
194+
#endif
185195

186196
} UARTName;
187197

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2017-2018 Nuvoton
1+
/*
2+
* Copyright (c) 2020, Nuvoton Technology Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
35
*
46
* Licensed under the Apache License, Version 2.0 (the "License");
57
* you may not use this file except in compliance with the License.
@@ -13,8 +15,8 @@
1315
* See the License for the specific language governing permissions and
1416
* limitations under the License.
1517
*/
16-
#ifndef MBED_PINNAMES_H
17-
#define MBED_PINNAMES_H
18+
#ifndef __PIN_NAMES_COMMON_H__
19+
#define __PIN_NAMES_COMMON_H__
1820

1921
#include "cmsis.h"
2022
#include "partition_M2351.h"
@@ -44,7 +46,7 @@ extern "C" {
4446
__STATIC_INLINE GPIO_T *NU_PORT_BASE(uint32_t PORT)
4547
{
4648
uint32_t port_base = ((uint32_t) GPIOA_BASE) + 0x40 * PORT;
47-
49+
4850
#if defined(SCU_INIT_IONSSET_VAL)
4951
if (SCU_INIT_IONSSET_VAL & (1 << (PORT + 0))) {
5052
port_base += NS_OFFSET;
@@ -65,7 +67,7 @@ __STATIC_INLINE uint32_t NU_GET_GPIO_PIN_DATA(uint32_t PORT, uint32_t PIN)
6567
return GPIO_PIN_DATA_NS(PORT, PIN);
6668
}
6769
#endif
68-
70+
6971
return GPIO_PIN_DATA_S(PORT, PIN);
7072
}
7173

@@ -78,7 +80,7 @@ __STATIC_INLINE void NU_SET_GPIO_PIN_DATA(uint32_t PORT, uint32_t PIN, uint32_t
7880
return;
7981
}
8082
#endif
81-
83+
8284
GPIO_PIN_DATA_S(PORT, PIN) = VALUE;
8385
}
8486

@@ -98,88 +100,19 @@ typedef enum {
98100
PullNone = 0,
99101
PullDown,
100102
PullUp,
101-
103+
102104
/* I/O mode */
103105
InputOnly,
104106
PushPullOutput,
105107
OpenDrain,
106108
QuasiBidirectional,
107-
109+
108110
/* Default input pull mode */
109111
PullDefault = PullUp
110112
} PinMode;
111113

112-
typedef enum {
113-
// Not connected
114-
NC = (int)0xFFFFFFFF,
115-
116-
// Generic naming
117-
PA_0 = NU_PORT_N_PIN_TO_PINNAME(0, 0), PA_1, PA_2, PA_3, PA_4, PA_5, PA_6, PA_7, PA_8, PA_9, PA_10, PA_11, PA_12, PA_13, PA_14, PA_15,
118-
PB_0 = NU_PORT_N_PIN_TO_PINNAME(1, 0), PB_1, PB_2, PB_3, PB_4, PB_5, PB_6, PB_7, PB_8, PB_9, PB_10, PB_11, PB_12, PB_13, PB_14, PB_15,
119-
PC_0 = NU_PORT_N_PIN_TO_PINNAME(2, 0), PC_1, PC_2, PC_3, PC_4, PC_5, PC_6, PC_7, PC_8, PC_9, PC_10, PC_11, PC_12, PC_13,
120-
PD_0 = NU_PORT_N_PIN_TO_PINNAME(3, 0), PD_1, PD_2, PD_3, PD_4, PD_5, PD_6, PD_7, PD_8, PD_9, PD_10, PD_11, PD_12, PD_13, PD_14,
121-
PE_0 = NU_PORT_N_PIN_TO_PINNAME(4, 0), PE_1, PE_2, PE_3, PE_4, PE_5, PE_6, PE_7, PE_8, PE_9, PE_10, PE_11, PE_12, PE_13, PE_14, PE_15,
122-
PF_0 = NU_PORT_N_PIN_TO_PINNAME(5, 0), PF_1, PF_2, PF_3, PF_4, PF_5, PF_6, PF_7, PF_8, PF_9, PF_10, PF_11,
123-
PG_0 = NU_PORT_N_PIN_TO_PINNAME(6, 0), PG_1, PG_2, PG_3, PG_4, PG_5, PG_6, PG_7, PG_8, PG_9, PG_10, PG_11, PG_12, PG_13, PG_14, PG_15,
124-
PH_0 = NU_PORT_N_PIN_TO_PINNAME(7, 0), PH_1, PH_2, PH_3, PH_4, PH_5, PH_6, PH_7, PH_8, PH_9, PH_10, PH_11,
125-
126-
// Arduino UNO naming
127-
A0 = PB_11,
128-
A1 = PB_10,
129-
A2 = PB_9,
130-
A3 = PB_8,
131-
A4 = PB_4,
132-
A5 = PB_5,
133-
134-
D0 = PA_8,
135-
D1 = PA_9,
136-
D2 = PB_7,
137-
D3 = PB_6,
138-
D4 = PB_3,
139-
D5 = PB_2,
140-
D6 = PC_12,
141-
D7 = PC_11,
142-
D8 = PC_9,
143-
D9 = PC_10,
144-
D10 = PF_9,
145-
D11 = PF_6,
146-
D12 = PF_7,
147-
D13 = PF_8,
148-
D14 = PG_3,
149-
D15 = PG_2,
150-
151-
// Other board-specific naming
152-
153-
// UART naming
154-
USBTX = PB_13,
155-
USBRX = PB_12,
156-
STDIO_UART_TX = USBTX,
157-
STDIO_UART_RX = USBRX,
158-
159-
// I2C naming
160-
I2C_SCL = D15,
161-
I2C_SDA = D14,
162-
163-
// LED naming
164-
LED1 = PA_10,
165-
LED2 = PA_11,
166-
LED3 = PA_10, // No real LED. Just for passing ATS.
167-
LED4 = PA_11, // No real LED. Just for passing ATS.
168-
LED_GREEN = LED1,
169-
170-
// Button naming
171-
SW2 = PB_0,
172-
SW3 = PB_1,
173-
BUTTON1 = SW2,
174-
BUTTON2 = SW3,
175-
176-
// Force PinName to 32-bit required by NU_PINNAME_BIND(...)
177-
FORCE_ENUM_PINNAME_32BIT = 0x7FFFFFFF,
178-
179-
} PinName;
180-
181114
#ifdef __cplusplus
182115
}
183116
#endif
184117

185-
#endif // MBED_PINNAMES_H
118+
#endif // __PIN_NAMES_COMMON_H__
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2018 Nuvoton
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+
#ifndef MBED_PINNAMES_H
17+
#define MBED_PINNAMES_H
18+
19+
#include "cmsis.h"
20+
#include "PinNamesCommon.h"
21+
#include "partition_M2351.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
typedef enum {
28+
// Not connected
29+
NC = (int)0xFFFFFFFF,
30+
31+
// Generic naming
32+
PA_0 = NU_PORT_N_PIN_TO_PINNAME(0, 0), PA_1, PA_2, PA_3, PA_4, PA_5, PA_6, PA_7, PA_8, PA_9, PA_10, PA_11, PA_12, PA_13, PA_14, PA_15,
33+
PB_0 = NU_PORT_N_PIN_TO_PINNAME(1, 0), PB_1, PB_2, PB_3, PB_4, PB_5, PB_6, PB_7, PB_8, PB_9, PB_10, PB_11, PB_12, PB_13, PB_14, PB_15,
34+
PC_0 = NU_PORT_N_PIN_TO_PINNAME(2, 0), PC_1, PC_2, PC_3, PC_4, PC_5, PC_6, PC_7, PC_8, PC_9, PC_10, PC_11, PC_12, PC_13,
35+
PD_0 = NU_PORT_N_PIN_TO_PINNAME(3, 0), PD_1, PD_2, PD_3, PD_4, PD_5, PD_6, PD_7, PD_8, PD_9, PD_10, PD_11, PD_12, PD_13, PD_14,
36+
PE_0 = NU_PORT_N_PIN_TO_PINNAME(4, 0), PE_1, PE_2, PE_3, PE_4, PE_5, PE_6, PE_7, PE_8, PE_9, PE_10, PE_11, PE_12, PE_13, PE_14, PE_15,
37+
PF_0 = NU_PORT_N_PIN_TO_PINNAME(5, 0), PF_1, PF_2, PF_3, PF_4, PF_5, PF_6, PF_7, PF_8, PF_9, PF_10, PF_11,
38+
PG_0 = NU_PORT_N_PIN_TO_PINNAME(6, 0), PG_1, PG_2, PG_3, PG_4, PG_5, PG_6, PG_7, PG_8, PG_9, PG_10, PG_11, PG_12, PG_13, PG_14, PG_15,
39+
PH_0 = NU_PORT_N_PIN_TO_PINNAME(7, 0), PH_1, PH_2, PH_3, PH_4, PH_5, PH_6, PH_7, PH_8, PH_9, PH_10, PH_11,
40+
41+
// Arduino UNO naming
42+
A0 = PB_11,
43+
A1 = PB_10,
44+
A2 = PB_9,
45+
A3 = PB_8,
46+
A4 = PB_4,
47+
A5 = PB_5,
48+
49+
D0 = PA_8,
50+
D1 = PA_9,
51+
D2 = PB_7,
52+
D3 = PB_6,
53+
D4 = PB_3,
54+
D5 = PB_2,
55+
D6 = PC_12,
56+
D7 = PC_11,
57+
D8 = PC_9,
58+
D9 = PC_10,
59+
D10 = PF_9,
60+
D11 = PF_6,
61+
D12 = PF_7,
62+
D13 = PF_8,
63+
D14 = PG_3,
64+
D15 = PG_2,
65+
66+
// Other board-specific naming
67+
68+
// UART naming
69+
#if defined(MBED_CONF_TARGET_USB_UART_TX)
70+
USBTX = MBED_CONF_TARGET_USB_UART_TX,
71+
#else
72+
USBTX = NC,
73+
#endif
74+
#if defined(MBED_CONF_TARGET_USB_UART_RX)
75+
USBRX = MBED_CONF_TARGET_USB_UART_RX,
76+
#else
77+
USBRX = NC,
78+
#endif
79+
#if defined(MBED_CONF_TARGET_STDIO_UART_TX)
80+
STDIO_UART_TX = MBED_CONF_TARGET_STDIO_UART_TX,
81+
#else
82+
STDIO_UART_TX = USBTX,
83+
#endif
84+
#if defined(MBED_CONF_TARGET_STDIO_UART_RX)
85+
STDIO_UART_RX = MBED_CONF_TARGET_STDIO_UART_RX,
86+
#else
87+
STDIO_UART_RX = USBRX,
88+
#endif
89+
90+
// I2C naming
91+
I2C_SCL = D15,
92+
I2C_SDA = D14,
93+
94+
// LED naming
95+
LED1 = PA_10,
96+
LED2 = PA_11,
97+
LED3 = PA_10, // No real LED. Just for passing ATS.
98+
LED4 = PA_11, // No real LED. Just for passing ATS.
99+
LED_GREEN = LED1,
100+
101+
// Button naming
102+
SW2 = PB_0,
103+
SW3 = PB_1,
104+
BUTTON1 = SW2,
105+
BUTTON2 = SW3,
106+
107+
// Force PinName to 32-bit required by NU_PINNAME_BIND(...)
108+
FORCE_ENUM_PINNAME_32BIT = 0x7FFFFFFF,
109+
110+
} PinName;
111+
112+
#ifdef __cplusplus
113+
}
114+
#endif
115+
116+
#endif // MBED_PINNAMES_H

targets/targets.json

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13142,12 +13142,12 @@
1314213142
"MPU"
1314313143
]
1314413144
},
13145-
"NU_PFM_M2351": {
13145+
"MCU_M2351": {
1314613146
"default_toolchain": "ARMC6",
13147+
"public": false,
1314713148
"extra_labels": [
1314813149
"NUVOTON",
1314913150
"M2351",
13150-
"M2351KIAAEES",
1315113151
"FLASH_CMSIS_ALGO"
1315213152
],
1315313153
"OUTPUT_EXT": "hex",
@@ -13157,6 +13157,30 @@
1315713157
],
1315813158
"is_disk_virtual": true,
1315913159
"config": {
13160+
"usb-uart": {
13161+
"help": "Configure USB_UART. USB_UART and USB_UART_TX/USB_UART_RX must be consistent.",
13162+
"value": null
13163+
},
13164+
"usb-uart-tx": {
13165+
"help": "Configure USBTX. USB_UART and USBTX/USBRX must be consistent.",
13166+
"value": null
13167+
},
13168+
"usb-uart-rx": {
13169+
"help": "Configure USBRX. USB_UART and USBTX/USBRX must be consistent.",
13170+
"value": null
13171+
},
13172+
"stdio-uart": {
13173+
"help": "Configure STDIO_UART. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART defaults to USB_UART.",
13174+
"value": null
13175+
},
13176+
"stdio-uart-tx": {
13177+
"help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to USBTX.",
13178+
"value": null
13179+
},
13180+
"stdio-uart-rx": {
13181+
"help": "Configure STDIO_UART_RX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_RX defaults to USBRX.",
13182+
"value": null
13183+
},
1316013184
"gpio-irq-debounce-enable": {
1316113185
"help": "Enable GPIO IRQ debounce",
1316213186
"value": 0
@@ -13209,16 +13233,26 @@
1320913233
"MPU",
1321013234
"USBDEVICE"
1321113235
],
13212-
"detect_code": [
13213-
"1305"
13214-
],
1321513236
"release_versions": [
1321613237
"5"
1321713238
],
13218-
"device_name": "M2351KIAAEES",
1321913239
"bootloader_supported": true,
13220-
"forced_reset_timeout": 3,
13221-
"public": false
13240+
"forced_reset_timeout": 3
13241+
},
13242+
"NU_PFM_M2351": {
13243+
"inherits": [
13244+
"MCU_M2351"
13245+
],
13246+
"detect_code": [
13247+
"1305"
13248+
],
13249+
"device_name": "M2351KIAAEES",
13250+
"public": false,
13251+
"overrides": {
13252+
"usb-uart": "UART_0",
13253+
"usb-uart-tx": "PB_13",
13254+
"usb-uart-rx": "PB_12"
13255+
}
1322213256
},
1322313257
"NU_PFM_M2351_NPSA_NS": {
1322413258
"inherits": [

0 commit comments

Comments
 (0)