Skip to content

Commit 8d73978

Browse files
authored
Merge pull request #5894 from bcostm/fix_serial_7bit
STM32: fix serial 7bit data format
2 parents 669a85a + 2cdc110 commit 8d73978

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

targets/TARGET_STM/serial_api.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,27 +474,34 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
474474
}
475475

476476
switch (data_bits) {
477-
case 9:
478-
MBED_ASSERT(parity == UART_PARITY_NONE);
479-
obj_s->databits = UART_WORDLENGTH_9B;
477+
case 7:
478+
if (parity != UART_PARITY_NONE) {
479+
obj_s->databits = UART_WORDLENGTH_8B;
480+
} else {
481+
#if defined UART_WORDLENGTH_7B
482+
obj_s->databits = UART_WORDLENGTH_7B;
483+
#else
484+
error("7-bit data format without parity is not supported");
485+
#endif
486+
}
480487
break;
481-
default:
482488
case 8:
483489
if (parity != UART_PARITY_NONE) {
484490
obj_s->databits = UART_WORDLENGTH_9B;
485491
} else {
486492
obj_s->databits = UART_WORDLENGTH_8B;
487493
}
488494
break;
489-
#if defined UART_WORDLENGTH_7B
490-
case 7:
495+
case 9:
491496
if (parity != UART_PARITY_NONE) {
492-
obj_s->databits = UART_WORDLENGTH_8B;
497+
error("Parity is not supported with 9-bit data format");
493498
} else {
494-
obj_s->databits = UART_WORDLENGTH_7B;
499+
obj_s->databits = UART_WORDLENGTH_9B;
495500
}
496501
break;
497-
#endif
502+
default:
503+
error("Only 7, 8 or 9-bit data formats are supported");
504+
break;
498505
}
499506

500507
if (stop_bits == 2) {

0 commit comments

Comments
 (0)