Skip to content

Commit c7fcd07

Browse files
committed
[NUC472/M453] Add sanity check for serial format
1 parent 5e335de commit c7fcd07

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

targets/TARGET_NUVOTON/TARGET_M451/serial_api.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
269269
// Flush Tx FIFO. Otherwise, output data may get lost on this change.
270270
while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart))));
271271

272-
// TODO: Assert for not supported parity and data bits
272+
// Sanity check arguments
273+
MBED_ASSERT((data_bits == 5) || (data_bits == 6) || (data_bits == 7) || (data_bits == 8));
274+
MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) || (parity == ParityForced1) || (parity == ParityForced0));
275+
MBED_ASSERT((stop_bits == 1) || (stop_bits == 2));
276+
273277
obj->serial.databits = data_bits;
274278
obj->serial.parity = parity;
275279
obj->serial.stopbits = stop_bits;

targets/TARGET_NUVOTON/TARGET_NUC472/serial_api.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
299299
// Flush Tx FIFO. Otherwise, output data may get lost on this change.
300300
while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart))));
301301

302-
// TODO: Assert for not supported parity and data bits
302+
// Sanity check arguments
303+
MBED_ASSERT((data_bits == 5) || (data_bits == 6) || (data_bits == 7) || (data_bits == 8));
304+
MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) || (parity == ParityForced1) || (parity == ParityForced0));
305+
MBED_ASSERT((stop_bits == 1) || (stop_bits == 2));
306+
303307
obj->serial.databits = data_bits;
304308
obj->serial.parity = parity;
305309
obj->serial.stopbits = stop_bits;

0 commit comments

Comments
 (0)