Skip to content

Commit

Permalink
Merge pull request #5894 from bcostm/fix_serial_7bit
Browse files Browse the repository at this point in the history
STM32: fix serial 7bit data format
  • Loading branch information
cmonr committed Jan 23, 2018
2 parents 669a85a + 2cdc110 commit 8d73978
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions targets/TARGET_STM/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,27 +474,34 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
}

switch (data_bits) {
case 9:
MBED_ASSERT(parity == UART_PARITY_NONE);
obj_s->databits = UART_WORDLENGTH_9B;
case 7:
if (parity != UART_PARITY_NONE) {
obj_s->databits = UART_WORDLENGTH_8B;
} else {
#if defined UART_WORDLENGTH_7B
obj_s->databits = UART_WORDLENGTH_7B;
#else
error("7-bit data format without parity is not supported");
#endif
}
break;
default:
case 8:
if (parity != UART_PARITY_NONE) {
obj_s->databits = UART_WORDLENGTH_9B;
} else {
obj_s->databits = UART_WORDLENGTH_8B;
}
break;
#if defined UART_WORDLENGTH_7B
case 7:
case 9:
if (parity != UART_PARITY_NONE) {
obj_s->databits = UART_WORDLENGTH_8B;
error("Parity is not supported with 9-bit data format");
} else {
obj_s->databits = UART_WORDLENGTH_7B;
obj_s->databits = UART_WORDLENGTH_9B;
}
break;
#endif
default:
error("Only 7, 8 or 9-bit data formats are supported");
break;
}

if (stop_bits == 2) {
Expand Down

0 comments on commit 8d73978

Please sign in to comment.