Merge pull request #12611 from jeromecoutant/PR_UART_PARITY

STM32F4 UART issue when parity enabled
pull/12633/head
Anna Bridge 2020-03-13 11:07:21 +00:00 committed by GitHub
commit d61187c23a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -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)
@ -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
@ -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
@ -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;;