Skip to content

Commit a76f5dc

Browse files
committed
M252: Support configurability of USB/STDIO UART pins
- STDIO_UART and STDIO_UART_TX/STDIO_UART_RX - USB_UART and USBTX/USBRX
1 parent f7e4a75 commit a76f5dc

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

targets/TARGET_NUVOTON/TARGET_M251/PeripheralNames.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define MBED_PERIPHERALNAMES_H
2121

2222
#include "cmsis.h"
23+
#include "PinNames.h"
2324

2425
#ifdef __cplusplus
2526
extern "C" {
@@ -77,7 +78,16 @@ typedef enum {
7778
UART_2 = (int) NU_MODNAME(UART2_BASE, 2, 0),
7879

7980
/* NOTE: board-specific */
80-
STDIO_UART = UART_0
81+
#if defined(MBED_CONF_TARGET_USB_UART)
82+
USB_UART = MBED_CONF_TARGET_USB_UART,
83+
#else
84+
USB_UART = NC,
85+
#endif
86+
#if defined(MBED_CONF_TARGET_STDIO_UART)
87+
STDIO_UART = MBED_CONF_TARGET_STDIO_UART
88+
#else
89+
STDIO_UART = USB_UART
90+
#endif
8191
} UARTName;
8292

8393
typedef enum {

targets/TARGET_NUVOTON/TARGET_M251/PinNames.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef enum {
7070
typedef enum {
7171
/* Not connected */
7272
NC = (int)0xFFFFFFFF,
73-
73+
7474
/* Generic naming */
7575
PA_0 = NU_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,
7676
PB_0 = NU_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,
@@ -103,21 +103,37 @@ typedef enum {
103103
D13 = PA_2,
104104
D14 = PC_0,
105105
D15 = PC_1,
106-
106+
107107
/* Other board-specific naming */
108-
108+
109109
/* UART naming */
110-
USBTX = PB_13,
111-
USBRX = PB_12,
110+
#if defined(MBED_CONF_TARGET_USB_UART_TX)
111+
USBTX = MBED_CONF_TARGET_USB_UART_TX,
112+
#else
113+
USBTX = NC,
114+
#endif
115+
#if defined(MBED_CONF_TARGET_USB_UART_RX)
116+
USBRX = MBED_CONF_TARGET_USB_UART_RX,
117+
#else
118+
USBRX = NC,
119+
#endif
120+
#if defined(MBED_CONF_TARGET_STDIO_UART_TX)
121+
STDIO_UART_TX = MBED_CONF_TARGET_STDIO_UART_TX,
122+
#else
112123
STDIO_UART_TX = USBTX,
124+
#endif
125+
#if defined(MBED_CONF_TARGET_STDIO_UART_RX)
126+
STDIO_UART_RX = MBED_CONF_TARGET_STDIO_UART_RX,
127+
#else
113128
STDIO_UART_RX = USBRX,
129+
#endif
114130
SERIAL_TX = D10,
115131
SERIAL_RX = D13,
116132

117133
/* I2C naming */
118134
I2C_SCL = D15,
119135
I2C_SDA = D14,
120-
136+
121137
/* LED naming */
122138
LED_RED = PB_14,
123139
LED1 = LED_RED,
@@ -126,7 +142,7 @@ typedef enum {
126142
LED4 = LED1, // No real LED. Just for passing ATS.
127143

128144
/* Button naming */
129-
145+
130146
/* Force PinName to 32-bit required by NU_PINNAME_BIND(...) */
131147
FORCE_ENUM_PINNAME_32BIT = 0x7FFFFFFF,
132148

targets/targets.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5656,6 +5656,30 @@
56565656
"IAR"
56575657
],
56585658
"config": {
5659+
"usb-uart": {
5660+
"help": "Configure USB_UART. USB_UART and USB_UART_TX/USB_UART_RX must be consistent.",
5661+
"value": null
5662+
},
5663+
"usb-uart-tx": {
5664+
"help": "Configure USBTX. USB_UART and USBTX/USBRX must be consistent.",
5665+
"value": null
5666+
},
5667+
"usb-uart-rx": {
5668+
"help": "Configure USBRX. USB_UART and USBTX/USBRX must be consistent.",
5669+
"value": null
5670+
},
5671+
"stdio-uart": {
5672+
"help": "Configure STDIO_UART. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART defaults to USB_UART.",
5673+
"value": null
5674+
},
5675+
"stdio-uart-tx": {
5676+
"help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to USBTX.",
5677+
"value": null
5678+
},
5679+
"stdio-uart-rx": {
5680+
"help": "Configure STDIO_UART_RX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_RX defaults to USBRX.",
5681+
"value": null
5682+
},
56595683
"gpio-irq-debounce-enable": {
56605684
"help": "Enable GPIO IRQ debounce",
56615685
"value": 0
@@ -5733,7 +5757,12 @@
57335757
"2",
57345758
"5"
57355759
],
5736-
"device_name": "M252KG6AE"
5760+
"device_name": "M252KG6AE",
5761+
"overrides": {
5762+
"usb-uart": "UART_0",
5763+
"usb-uart-tx": "PB_13",
5764+
"usb-uart-rx": "PB_12"
5765+
}
57375766
},
57385767
"TMPM4G9": {
57395768
"inherits": [

0 commit comments

Comments
 (0)