Skip to content

STM32: fix serial 7bit data format #5894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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