From 3d719f7e357ec96083cea076c6038cd2b65f50fc Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 12 Sep 2019 10:28:36 +0200 Subject: [PATCH] K64F, NUCLEO_F429ZI: Use explicit pinmap for console --- platform/source/mbed_retarget.cpp | 51 +++++++++++++++---- .../TARGET_MCU_K64F/TARGET_FRDM/PinNames.h | 5 +- .../TARGET_NUCLEO_F429ZI/PinNames.h | 3 ++ 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 10b7f55892..e77ba90a73 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -33,6 +33,7 @@ #include "drivers/UARTSerial.h" #include "hal/us_ticker_api.h" #include "hal/lp_ticker_api.h" +#include "hal/explicit_pinmap.h" #include #include #include @@ -154,6 +155,7 @@ extern serial_t stdio_uart; class DirectSerial : public FileHandle { public: DirectSerial(PinName tx, PinName rx, int baud); + DirectSerial(const serial_pinmap_t &explicit_pinmap, int baud); virtual ssize_t write(const void *buffer, size_t size); virtual ssize_t read(void *buffer, size_t size); virtual off_t seek(off_t offset, int whence = SEEK_SET) @@ -180,14 +182,39 @@ DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) if (stdio_uart_inited) { return; } - serial_init(&stdio_uart, tx, rx); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + serial_init_direct(&stdio_uart, &console_pinmap); serial_baud(&stdio_uart, baud); + #if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS - serial_set_flow_control(&stdio_uart, FlowControlRTS, STDIO_UART_RTS, NC); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS - serial_set_flow_control(&stdio_uart, FlowControlCTS, NC, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS - serial_set_flow_control(&stdio_uart, FlowControlRTSCTS, STDIO_UART_RTS, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, fc_pinmap); +#endif +} + +DirectSerial::DirectSerial(const serial_pinmap_t &explicit_pinmap, int baud) +{ + if (stdio_uart_inited) { + return; + } + serial_init_direct(&stdio_uart, &explicit_pinmap); + serial_baud(&stdio_uart, baud); + +#if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, fc_pinmap); +#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, fc_pinmap); +#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, fc_pinmap); #endif } @@ -303,17 +330,23 @@ MBED_WEAK FileHandle *mbed::mbed_override_console(int fd) static FileHandle *default_console() { #if MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL + # if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL - static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + static UARTSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS - console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); + console.serial_set_flow_control(SerialBase::RTS, fc_pinmap); # elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS - console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); + console.serial_set_flow_control(SerialBase::CTS, fc_pinmap); # elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS - console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); + console.serial_set_flow_control(SerialBase::RTSCTS, fc_pinmap); # endif # else - static DirectSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + static DirectSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # endif #else // MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL static Sink console; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h index a2a388eb10..d518d29863 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h @@ -22,6 +22,9 @@ extern "C" { #endif +/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */ +#define EXPLICIT_PINMAP_READY 1 + typedef enum { PIN_INPUT, PIN_OUTPUT @@ -229,7 +232,7 @@ typedef enum { D13 = PTD1, D14 = PTE25, D15 = PTE24, - + I2C_SCL = D15, I2C_SDA = D14, diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h index 7568cac5db..94c3c40125 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h @@ -38,6 +38,9 @@ extern "C" { #endif +/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */ +#define EXPLICIT_PINMAP_READY 1 + typedef enum { ALT0 = 0x100, ALT1 = 0x200,