Skip to content

Commit 722e897

Browse files
committed
[MAX32625] Prevent serial activity if tx/rx pin is NC.
1 parent 0784f03 commit 722e897

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

targets/TARGET_Maxim/TARGET_MAX32625/objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ struct serial_s {
7575
uint32_t id;
7676
uart_cfg_t cfg;
7777
sys_cfg_uart_t sys_cfg;
78-
PinName tx_pin;
78+
PinName tx;
79+
PinName rx;
7980
};
8081

8182
struct i2c_s {

targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
8181
memcpy(&stdio_uart, obj, sizeof(serial_t));
8282
}
8383

84-
// Save transmit pin for break function
85-
obj->tx_pin = tx;
84+
// Record the pins requested
85+
obj->tx = tx;
86+
obj->rx = rx;
8687

8788
// Merge pin function requests for use with CMSIS init func
8889
ioman_req_t io_req = {0};
@@ -249,26 +250,30 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
249250
//******************************************************************************
250251
int serial_getc(serial_t *obj)
251252
{
252-
int c;
253+
int c = 0;
253254

254-
// Wait for data to be available
255-
while ((obj->uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY) == 0);
255+
if (obj->rx != NC) {
256+
// Wait for data to be available
257+
while ((obj->uart->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY) == 0);
256258

257-
c = obj->fifo->rx;
259+
c = obj->fifo->rx;
260+
}
258261

259262
return c;
260263
}
261264

262265
//******************************************************************************
263266
void serial_putc(serial_t *obj, int c)
264267
{
265-
// Wait for room in the FIFO without blocking interrupts.
266-
while (UART_NumWriteAvail(obj->uart) == 0);
267-
268-
// Must clear before every write to the buffer to know that the FIFO
269-
// is empty when the TX DONE bit is set
270-
obj->uart->intfl = MXC_F_UART_INTFL_TX_DONE;
271-
obj->fifo->tx = (uint8_t)c;
268+
if (obj->tx != NC) {
269+
// Wait for room in the FIFO without blocking interrupts.
270+
while (UART_NumWriteAvail(obj->uart) == 0);
271+
272+
// Must clear before every write to the buffer to know that the FIFO
273+
// is empty when the TX DONE bit is set
274+
obj->uart->intfl = MXC_F_UART_INTFL_TX_DONE;
275+
obj->fifo->tx = (uint8_t)c;
276+
}
272277
}
273278

274279
//******************************************************************************
@@ -300,10 +305,10 @@ void serial_break_set(serial_t *obj)
300305
while (!(obj->uart->intfl & MXC_F_UART_INTFL_TX_DONE));
301306

302307
// Configure TX to output 0
303-
usurp_pin(obj->tx_pin, 0);
308+
usurp_pin(obj->tx, 0);
304309

305310
// GPIO is setup now, but we need to unmap UART from the pin
306-
pin_function_t *pin_func = (pin_function_t *)pinmap_find_function(obj->tx_pin, PinMap_UART_TX);
311+
pin_function_t *pin_func = (pin_function_t *)pinmap_find_function(obj->tx, PinMap_UART_TX);
307312
*pin_func->reg_req &= ~MXC_F_IOMAN_UART_REQ_IO_REQ;
308313
MBED_ASSERT((*pin_func->reg_ack & MXC_F_IOMAN_UART_ACK_IO_ACK) == 0);
309314
}
@@ -312,9 +317,9 @@ void serial_break_set(serial_t *obj)
312317
void serial_break_clear(serial_t *obj)
313318
{
314319
// Configure TX to output 1
315-
usurp_pin(obj->tx_pin, 1);
320+
usurp_pin(obj->tx, 1);
316321
// Return TX to UART control
317-
serial_pinout_tx(obj->tx_pin);
322+
serial_pinout_tx(obj->tx);
318323
}
319324

320325
//******************************************************************************

0 commit comments

Comments
 (0)