From d239ef98cd02b9f6839098b787e37f2419d2eed5 Mon Sep 17 00:00:00 2001 From: George Psimenos Date: Wed, 10 Mar 2021 14:14:26 +0000 Subject: [PATCH] Rename USBTX/RX to CONSOLE_TX/RX --- .../{ArduinoUnoAliases.h => PinNameAliases.h} | 15 +++++++++--- hal/include/hal/static_pinmap.h | 3 ++- hal/source/mbed_gpio.c | 2 +- hal/source/mbed_pinmap_default.cpp | 6 ++--- .../TESTS/pin_names/arduino_uno/main.cpp | 8 +++---- hal/tests/pinvalidate/pinvalidate.py | 17 +++++++++++-- hal/tests/pinvalidate/pinvalidate_test.py | 4 ++-- hal/tests/pinvalidate/test_files/PinNames.h | 4 ++-- .../pinvalidate/test_files/PinNames_test.h | 4 ++-- .../test_files/duplicate_file/PinNames.h | 4 ++-- .../test_files/duplicate_marker/PinNames.h | 4 ++-- .../test_files/misformatted_marker/PinNames.h | 4 ++-- .../test_files/missing_marker/PinNames.h | 4 ++-- .../test_files/nonexistent_target/PinNames.h | 4 ++-- platform/include/platform/platform.h | 2 +- platform/source/mbed_retarget.cpp | 8 +++---- targets/targets.json | 24 +++++++++---------- 17 files changed, 70 insertions(+), 47 deletions(-) rename hal/include/hal/{ArduinoUnoAliases.h => PinNameAliases.h} (89%) diff --git a/hal/include/hal/ArduinoUnoAliases.h b/hal/include/hal/PinNameAliases.h similarity index 89% rename from hal/include/hal/ArduinoUnoAliases.h rename to hal/include/hal/PinNameAliases.h index 7485c3e93f..761e415943 100644 --- a/hal/include/hal/ArduinoUnoAliases.h +++ b/hal/include/hal/PinNameAliases.h @@ -17,8 +17,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MBED_ARDUINO_UNO_H -#define MBED_ARDUINO_UNO_H +#ifndef MBED_PIN_NAME_ALIASES_H +#define MBED_PIN_NAME_ALIASES_H + +/* Aliases for legacy reasons. To be removed in the next Mbed OS version */ +#if defined (CONSOLE_TX) && (CONSOLE_RX) +#define USBTX CONSOLE_TX +#define USBRX CONSOLE_RX +#else +#define CONSOLE_TX USBTX +#define CONSOLE_RX USBRX +#endif #if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO) @@ -94,6 +103,6 @@ #endif // (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO) -#endif // MBED_ARDUINO_UNO_H +#endif // MBED_PIN_NAME_ALIASES_H /** @}*/ diff --git a/hal/include/hal/static_pinmap.h b/hal/include/hal/static_pinmap.h index de04fe9358..cfa5458e31 100644 --- a/hal/include/hal/static_pinmap.h +++ b/hal/include/hal/static_pinmap.h @@ -17,6 +17,7 @@ #ifndef STATIC_PINMAP_H #define STATIC_PINMAP_H +#include "hal/PinNameAliases.h" #include "PinNames.h" #include "spi_api.h" #include "pwmout_api.h" @@ -128,7 +129,7 @@ MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const Pin return {(int) NC, NC, (int) NC, NC, (int) NC, false}; } - if (tx_map->pin == USBTX && rx_map->pin == USBRX) { + if (tx_map->pin == CONSOLE_TX && rx_map->pin == CONSOLE_RX) { return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, true}; } else { return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false}; diff --git a/hal/source/mbed_gpio.c b/hal/source/mbed_gpio.c index bfc550c0c7..f2e1f34626 100644 --- a/hal/source/mbed_gpio.c +++ b/hal/source/mbed_gpio.c @@ -16,7 +16,7 @@ */ #include "hal/gpio_api.h" #include "platform/mbed_toolchain.h" -#include "hal/ArduinoUnoAliases.h" +#include "hal/PinNameAliases.h" static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode) { diff --git a/hal/source/mbed_pinmap_default.cpp b/hal/source/mbed_pinmap_default.cpp index 0b05233016..1290b8d58e 100644 --- a/hal/source/mbed_pinmap_default.cpp +++ b/hal/source/mbed_pinmap_default.cpp @@ -21,7 +21,7 @@ #include "platform/mbed_assert.h" #include "device.h" #include "hal/serial_api.h" -#include "hal/ArduinoUnoAliases.h" +#include "hal/PinNameAliases.h" //*** Common form factors *** #if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO) @@ -70,7 +70,7 @@ const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin) MBED_WEAK const PinList *pinmap_restricted_pins() { static const PinName pins[] = { - USBTX, USBRX + CONSOLE_TX, CONSOLE_RX }; static const PinList pin_list = { sizeof(pins) / sizeof(pins[0]), @@ -94,7 +94,7 @@ MBED_WEAK const PinList *pinmap_gpio_restricted_pins() #if DEVICE_SERIAL MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals() { - static const int stdio_uart = pinmap_peripheral(USBTX, serial_tx_pinmap()); + static const int stdio_uart = pinmap_peripheral(CONSOLE_TX, serial_tx_pinmap()); static const int peripherals[] = { stdio_uart diff --git a/hal/tests/TESTS/pin_names/arduino_uno/main.cpp b/hal/tests/TESTS/pin_names/arduino_uno/main.cpp index b2b9bdc3bc..2a10b93799 100644 --- a/hal/tests/TESTS/pin_names/arduino_uno/main.cpp +++ b/hal/tests/TESTS/pin_names/arduino_uno/main.cpp @@ -35,8 +35,8 @@ void GPIO_test() { utest_printf("GPIO Pin 0x%x\n", TestedPin); - TEST_SKIP_UNLESS_MESSAGE(TestedPin != USBTX, "ARDUINO_UNO pin shared with USBTX"); - TEST_SKIP_UNLESS_MESSAGE(TestedPin != USBRX, "ARDUINO_UNO pin shared with USBRX"); + TEST_SKIP_UNLESS_MESSAGE(TestedPin != CONSOLE_TX, "ARDUINO_UNO pin shared with CONSOLE_TX"); + TEST_SKIP_UNLESS_MESSAGE(TestedPin != CONSOLE_RX, "ARDUINO_UNO pin shared with CONSOLE_RX"); const PinMap *maps = gpio_pinmap(); // hal/source/mbed_gpio.c while (maps->pin != (PinName)NC) { // check each pin from PinMap table till NC pin @@ -124,8 +124,8 @@ void UART_test() { utest_printf("UART TX Pin 0x%x RX Pin 0x%x\n", TX_pin, RX_pin); - TEST_SKIP_UNLESS_MESSAGE(TX_pin != USBTX, "ARDUINO_UNO_UART pin shared with USBTX"); - TEST_SKIP_UNLESS_MESSAGE(RX_pin != USBRX, "ARDUINO_UNO_UART pin shared with USBRX"); + TEST_SKIP_UNLESS_MESSAGE(TX_pin != CONSOLE_TX, "ARDUINO_UNO_UART pin shared with CONSOLE_TX"); + TEST_SKIP_UNLESS_MESSAGE(RX_pin != CONSOLE_RX, "ARDUINO_UNO_UART pin shared with CONSOLE_RX"); { const PinMap *maps = serial_tx_pinmap(); diff --git a/hal/tests/pinvalidate/pinvalidate.py b/hal/tests/pinvalidate/pinvalidate.py index ba398d6f39..bf7fbf5a3c 100755 --- a/hal/tests/pinvalidate/pinvalidate.py +++ b/hal/tests/pinvalidate/pinvalidate.py @@ -314,7 +314,7 @@ def identity_assignment_check(pin_name_dict): def nc_assignment_check(pin_name_dict): invalid_items = [] for key, val in pin_name_dict.items(): - if re.match(r"^((LED|BUTTON)\d*|USBTX|USBRX)$", key): + if re.match(r"^((LED|BUTTON)\d*|CONSOLE_TX|CONSOLE_RX|USBTX|USBRX)$", key): if val == "NC": message = "cannot be NC" invalid_items.append( @@ -329,7 +329,7 @@ def duplicate_assignment_check(pin_name_dict): invalid_items = [] for key, val in pin_name_dict.items(): - if re.match(r"^((LED|BUTTON)\d*|USBTX|USBRX)$", key): + if re.match(r"^((LED|BUTTON)\d*|CONSOLE_TX|CONSOLE_RX|USBTX|USBRX)$", key): if val == "NC": continue # resolve to literal @@ -438,6 +438,13 @@ def legacy_assignment_check(pin_name_content): invalid_items.append({"key": key, "val": val, "message": message}) return invalid_items +def legacy_uart_check(pin_name_dict): + invalid_items = [] + if "CONSOLE_TX" not in pin_name_dict or "CONSOLE_RX" not in pin_name_dict: + message = "CONSOLE_TX or CONSOLE_RX are not defined; USBTX and USBRX are deprecated" + invalid_items.append({"key": "", "val": "", "message": message}) + return invalid_items + def print_summary(report): targets = set([case["platform_name"] for case in report]) @@ -653,6 +660,12 @@ test_cases = [ "case_function": legacy_assignment_check, "case_input": "content", }, + { + "suite_name": "generic", + "case_name": "uart", + "case_function": legacy_uart_check, + "case_input": "content", + }, { "suite_name": "arduino_uno", "case_name": "duplicate", diff --git a/hal/tests/pinvalidate/pinvalidate_test.py b/hal/tests/pinvalidate/pinvalidate_test.py index 07f4e21c4a..a3bd118c33 100644 --- a/hal/tests/pinvalidate/pinvalidate_test.py +++ b/hal/tests/pinvalidate/pinvalidate_test.py @@ -139,8 +139,8 @@ def test_pin_name_to_dict(pin_name_dict): "ARDUINO_UNO_D13": "PA_5", "ARDUINO_UNO_D14": "PB_9", "ARDUINO_UNO_D15": "PB_8", - "USBTX": "PB_6", - "USBRX": "PB_7", + "CONSOLE_TX": "PB_6", + "CONSOLE_RX": "PB_7", "LED1": "PA_5", "BUTTON1": "PC_2", "LED2": "PB_14", diff --git a/hal/tests/pinvalidate/test_files/PinNames.h b/hal/tests/pinvalidate/test_files/PinNames.h index 97895e8680..23ad63832d 100644 --- a/hal/tests/pinvalidate/test_files/PinNames.h +++ b/hal/tests/pinvalidate/test_files/PinNames.h @@ -82,8 +82,8 @@ typedef enum { LED3 = P1_21, LED4 = P1_23, #endif - USBTX = P0_2, - USBRX = P0_3, + CONSOLE_TX = P0_2, + CONSOLE_RX = P0_3, // Arch Pro Pin Names D0 = P4_29, diff --git a/hal/tests/pinvalidate/test_files/PinNames_test.h b/hal/tests/pinvalidate/test_files/PinNames_test.h index 1fc3d96d52..03e2b7304f 100644 --- a/hal/tests/pinvalidate/test_files/PinNames_test.h +++ b/hal/tests/pinvalidate/test_files/PinNames_test.h @@ -119,8 +119,8 @@ typedef enum { ARDUINO_UNO_D15 = PB_8, // I2C SCL / GPIO // valid STDIO definitions for console print - USBTX = PB_6, - USBRX = PB_7, + CONSOLE_TX = PB_6, + CONSOLE_RX = PB_7, // invalid legacy LED/BUTTON definitions // these should be a #define, not in an enum diff --git a/hal/tests/pinvalidate/test_files/duplicate_file/PinNames.h b/hal/tests/pinvalidate/test_files/duplicate_file/PinNames.h index 4bad41203b..3c8cbe0357 100644 --- a/hal/tests/pinvalidate/test_files/duplicate_file/PinNames.h +++ b/hal/tests/pinvalidate/test_files/duplicate_file/PinNames.h @@ -82,8 +82,8 @@ typedef enum { LED3 = P1_21, LED4 = P1_23, #endif - USBTX = P0_2, - USBRX = P0_3, + CONSOLE_TX = P0_2, + CONSOLE_RX = P0_3, // Arch Pro Pin Names D0 = P4_29, diff --git a/hal/tests/pinvalidate/test_files/duplicate_marker/PinNames.h b/hal/tests/pinvalidate/test_files/duplicate_marker/PinNames.h index 97895e8680..23ad63832d 100644 --- a/hal/tests/pinvalidate/test_files/duplicate_marker/PinNames.h +++ b/hal/tests/pinvalidate/test_files/duplicate_marker/PinNames.h @@ -82,8 +82,8 @@ typedef enum { LED3 = P1_21, LED4 = P1_23, #endif - USBTX = P0_2, - USBRX = P0_3, + CONSOLE_TX = P0_2, + CONSOLE_RX = P0_3, // Arch Pro Pin Names D0 = P4_29, diff --git a/hal/tests/pinvalidate/test_files/misformatted_marker/PinNames.h b/hal/tests/pinvalidate/test_files/misformatted_marker/PinNames.h index aa431019e4..abfe45918b 100644 --- a/hal/tests/pinvalidate/test_files/misformatted_marker/PinNames.h +++ b/hal/tests/pinvalidate/test_files/misformatted_marker/PinNames.h @@ -82,8 +82,8 @@ typedef enum { LED3 = P1_21, LED4 = P1_23, #endif - USBTX = P0_2, - USBRX = P0_3, + CONSOLE_TX = P0_2, + CONSOLE_RX = P0_3, // Arch Pro Pin Names D0 = P4_29, diff --git a/hal/tests/pinvalidate/test_files/missing_marker/PinNames.h b/hal/tests/pinvalidate/test_files/missing_marker/PinNames.h index 4e3a4d9507..4f071ef53f 100644 --- a/hal/tests/pinvalidate/test_files/missing_marker/PinNames.h +++ b/hal/tests/pinvalidate/test_files/missing_marker/PinNames.h @@ -80,8 +80,8 @@ typedef enum { LED3 = P1_21, LED4 = P1_23, #endif - USBTX = P0_2, - USBRX = P0_3, + CONSOLE_TX = P0_2, + CONSOLE_RX = P0_3, // Arch Pro Pin Names D0 = P4_29, diff --git a/hal/tests/pinvalidate/test_files/nonexistent_target/PinNames.h b/hal/tests/pinvalidate/test_files/nonexistent_target/PinNames.h index 3d07b66796..ab394a3545 100644 --- a/hal/tests/pinvalidate/test_files/nonexistent_target/PinNames.h +++ b/hal/tests/pinvalidate/test_files/nonexistent_target/PinNames.h @@ -82,8 +82,8 @@ typedef enum { LED3 = P1_21, LED4 = P1_23, #endif - USBTX = P0_2, - USBRX = P0_3, + CONSOLE_TX = P0_2, + CONSOLE_RX = P0_3, // Arch Pro Pin Names D0 = P4_29, diff --git a/platform/include/platform/platform.h b/platform/include/platform/platform.h index 06aaf21fc5..f484ee306a 100644 --- a/platform/include/platform/platform.h +++ b/platform/include/platform/platform.h @@ -28,7 +28,7 @@ #include "device.h" #include "PinNames.h" #include "PeripheralNames.h" -#include "hal/ArduinoUnoAliases.h" +#include "hal/PinNameAliases.h" /** \defgroup platform-public-api Platform * \ingroup mbed-os-public diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 9dadc9e860..57cef972c4 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -181,7 +181,7 @@ DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) return; } - static const serial_pinmap_t console_pinmap = get_uart_pinmap(USBTX, USBRX); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(CONSOLE_TX, CONSOLE_RX); serial_init_direct(&stdio_uart, &console_pinmap); serial_baud(&stdio_uart, baud); @@ -256,7 +256,7 @@ static void do_serial_init() return; } - static const serial_pinmap_t console_pinmap = get_uart_pinmap(USBTX, USBRX); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(CONSOLE_TX, CONSOLE_RX); serial_init_direct(&stdio_uart, &console_pinmap); serial_baud(&stdio_uart, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); #if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS @@ -335,7 +335,7 @@ static FileHandle *default_console() #if MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL # if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL - static const serial_pinmap_t console_pinmap = get_uart_pinmap(USBTX, USBRX); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(CONSOLE_TX, CONSOLE_RX); static BufferedSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); @@ -348,7 +348,7 @@ static FileHandle *default_console() console.serial_set_flow_control(SerialBase::RTSCTS, fc_pinmap); # endif # else - static const serial_pinmap_t console_pinmap = get_uart_pinmap(USBTX, USBRX); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(CONSOLE_TX, CONSOLE_RX); static DirectSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # endif #else // MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL diff --git a/targets/targets.json b/targets/targets.json index 29a86460b8..ee6d057b98 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -34,7 +34,7 @@ ], "config": { "console-uart": { - "help": "Target has UART console on pins USBTX, USBRX. Value is only significant if target has SERIAL device.", + "help": "Target has UART console on pins CONSOLE_TX, CONSOLE_RX. Value is only significant if target has SERIAL device.", "value": true }, "console-uart-flow-control": { @@ -6370,11 +6370,11 @@ "value": null }, "usb-uart-tx": { - "help": "Configure USBTX. USB_UART and USBTX/USBRX must be consistent.", + "help": "Configure CONSOLE_TX. USB_UART and CONSOLE_TX/CONSOLE_RX must be consistent.", "value": null }, "usb-uart-rx": { - "help": "Configure USBRX. USB_UART and USBTX/USBRX must be consistent.", + "help": "Configure CONSOLE_RX. USB_UART and CONSOLE_TX/CONSOLE_RX must be consistent.", "value": null }, "stdio-uart": { @@ -6382,11 +6382,11 @@ "value": null }, "stdio-uart-tx": { - "help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to USBTX.", + "help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to CONSOLE_TX.", "value": null }, "stdio-uart-rx": { - "help": "Configure STDIO_UART_RX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_RX defaults to USBRX.", + "help": "Configure STDIO_UART_RX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_RX defaults to CONSOLE_RX.", "value": null }, "gpio-irq-debounce-enable": { @@ -6719,11 +6719,11 @@ "value": null }, "usb-uart-tx": { - "help": "Configure USBTX. USB_UART and USBTX/USBRX must be consistent.", + "help": "Configure CONSOLE_TX. USB_UART and CONSOLE_TX/CONSOLE_RX must be consistent.", "value": null }, "usb-uart-rx": { - "help": "Configure USBRX. USB_UART and USBTX/USBRX must be consistent.", + "help": "Configure CONSOLE_RX. USB_UART and CONSOLE_TX/CONSOLE_RX must be consistent.", "value": null }, "stdio-uart": { @@ -6731,11 +6731,11 @@ "value": null }, "stdio-uart-tx": { - "help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to USBTX.", + "help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to CONSOLE_TX.", "value": null }, "stdio-uart-rx": { - "help": "Configure STDIO_UART_RX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_RX defaults to USBRX.", + "help": "Configure STDIO_UART_RX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_RX defaults to CONSOLE_RX.", "value": null }, "gpio-irq-debounce-enable": { @@ -7642,11 +7642,11 @@ "value": null }, "usb-uart-tx": { - "help": "Configure USBTX. USB_UART and USBTX/USBRX must be consistent.", + "help": "Configure CONSOLE_TX. USB_UART and CONSOLE_TX/CONSOLE_RX must be consistent.", "value": null }, "usb-uart-rx": { - "help": "Configure USBRX. USB_UART and USBTX/USBRX must be consistent.", + "help": "Configure CONSOLE_RX. USB_UART and CONSOLE_TX/CONSOLE_RX must be consistent.", "value": null }, "stdio-uart": { @@ -7654,7 +7654,7 @@ "value": null }, "stdio-uart-tx": { - "help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to USBTX.", + "help": "Configure STDIO_UART_TX. STDIO_UART and STDIO_UART_TX/STDIO_UART_RX must be consistent. STDIO_UART_TX defaults to CONSOLE_TX.", "value": null }, "stdio-uart-rx": {