From 722e89784ce50e581e6c26e83644843043455783 Mon Sep 17 00:00:00 2001 From: Jeremy Brodt <jeremy.brodt@maximintegrated.com> Date: Tue, 25 Oct 2016 09:44:54 -0500 Subject: [PATCH] [MAX32625] Prevent serial activity if tx/rx pin is NC. --- .../TARGET_Maxim/TARGET_MAX32625/objects.h | 3 +- .../TARGET_Maxim/TARGET_MAX32625/serial_api.c | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/objects.h b/targets/TARGET_Maxim/TARGET_MAX32625/objects.h index 53d1371a4e..26b4488ee3 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32625/objects.h +++ b/targets/TARGET_Maxim/TARGET_MAX32625/objects.h @@ -75,7 +75,8 @@ struct serial_s { uint32_t id; uart_cfg_t cfg; sys_cfg_uart_t sys_cfg; - PinName tx_pin; + PinName tx; + PinName rx; }; struct i2c_s { diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c index eab9d1e05b..6b2d85b75d 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c +++ b/targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c @@ -81,8 +81,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) memcpy(&stdio_uart, obj, sizeof(serial_t)); } - // Save transmit pin for break function - obj->tx_pin = tx; + // Record the pins requested + obj->tx = tx; + obj->rx = rx; // Merge pin function requests for use with CMSIS init func ioman_req_t io_req = {0}; @@ -249,12 +250,14 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) //****************************************************************************** int serial_getc(serial_t *obj) { - int c; + int c = 0; - // Wait for data to be available - while ((obj->uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY) == 0); + if (obj->rx != NC) { + // Wait for data to be available + while ((obj->uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY) == 0); - c = obj->fifo->rx; + c = obj->fifo->rx; + } return c; } @@ -262,13 +265,15 @@ int serial_getc(serial_t *obj) //****************************************************************************** void serial_putc(serial_t *obj, int c) { - // Wait for room in the FIFO without blocking interrupts. - while (UART_NumWriteAvail(obj->uart) == 0); + if (obj->tx != NC) { + // Wait for room in the FIFO without blocking interrupts. + while (UART_NumWriteAvail(obj->uart) == 0); - // Must clear before every write to the buffer to know that the FIFO - // is empty when the TX DONE bit is set - obj->uart->intfl = MXC_F_UART_INTFL_TX_DONE; - obj->fifo->tx = (uint8_t)c; + // Must clear before every write to the buffer to know that the FIFO + // is empty when the TX DONE bit is set + obj->uart->intfl = MXC_F_UART_INTFL_TX_DONE; + obj->fifo->tx = (uint8_t)c; + } } //****************************************************************************** @@ -300,10 +305,10 @@ void serial_break_set(serial_t *obj) while (!(obj->uart->intfl & MXC_F_UART_INTFL_TX_DONE)); // Configure TX to output 0 - usurp_pin(obj->tx_pin, 0); + usurp_pin(obj->tx, 0); // GPIO is setup now, but we need to unmap UART from the pin - pin_function_t *pin_func = (pin_function_t *)pinmap_find_function(obj->tx_pin, PinMap_UART_TX); + pin_function_t *pin_func = (pin_function_t *)pinmap_find_function(obj->tx, PinMap_UART_TX); *pin_func->reg_req &= ~MXC_F_IOMAN_UART_REQ_IO_REQ; MBED_ASSERT((*pin_func->reg_ack & MXC_F_IOMAN_UART_ACK_IO_ACK) == 0); } @@ -312,9 +317,9 @@ void serial_break_set(serial_t *obj) void serial_break_clear(serial_t *obj) { // Configure TX to output 1 - usurp_pin(obj->tx_pin, 1); + usurp_pin(obj->tx, 1); // Return TX to UART control - serial_pinout_tx(obj->tx_pin); + serial_pinout_tx(obj->tx); } //******************************************************************************