Skip to content

STM32F4 UART issue when parity enabled #12611

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
Mar 13, 2020
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
19 changes: 14 additions & 5 deletions targets/TARGET_STM/TARGET_STM32F4/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,16 @@ int serial_getc(serial_t *obj)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_readable(obj));
return (int)(huart->Instance->DR & 0x1FF);
if (obj_s->parity == UART_PARITY_NONE) {
return (int)(huart->Instance->DR & 0x1FF);
} else {
// When receiving with the parity enabled, the value read in the MSB bit is the received parity bit
if (obj_s->databits == UART_WORDLENGTH_8B) {
return (int)(huart->Instance->DR & 0x07F); // 7 data bits + 1 parity bit
} else {
return (int)(huart->Instance->DR & 0x0FF); // 8 data bits + 1 parity bit
}
}
}

void serial_putc(serial_t *obj, int c)
Expand Down Expand Up @@ -743,7 +752,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
}
if (type == FlowControlRTS) {
// Enable RTS
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
MBED_ASSERT(pinmap->rx_flow_pin != NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS;
obj_s->pin_rts = pinmap->rx_flow_pin;
// Enable the pin for RTS function
Expand All @@ -752,7 +761,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
}
if (type == FlowControlCTS) {
// Enable CTS
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
MBED_ASSERT(pinmap->tx_flow_pin != NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_CTS;
obj_s->pin_cts = pinmap->tx_flow_pin;
// Enable the pin for CTS function
Expand All @@ -761,8 +770,8 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
}
if (type == FlowControlRTSCTS) {
// Enable CTS & RTS
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
MBED_ASSERT(pinmap->rx_flow_pin != NC);
MBED_ASSERT(pinmap->tx_flow_pin != NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS;
obj_s->pin_rts = pinmap->rx_flow_pin;;
obj_s->pin_cts = pinmap->tx_flow_pin;;
Expand Down