From a2dd2f9c089bfda72c1e219c9902bea1a74f31d4 Mon Sep 17 00:00:00 2001 From: mikeller Date: Mon, 5 Jun 2017 09:23:57 +1200 Subject: [PATCH] Changed serial word length to be 9 bits with parity when HAL is used. --- src/main/drivers/serial_uart_hal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index 58a7d38e3..a21ab9686 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -75,7 +75,9 @@ void uartReconfigure(uartPort_t *uartPort) HAL_UART_DeInit(&uartPort->Handle); uartPort->Handle.Init.BaudRate = uartPort->port.baudRate; - uartPort->Handle.Init.WordLength = UART_WORDLENGTH_8B; + // according to the stm32 documentation wordlen has to be 9 for parity bits + // this does not seem to matter for rx but will give bad data on tx! + uartPort->Handle.Init.WordLength = (uartPort->port.options & SERIAL_PARITY_EVEN) ? UART_WORDLENGTH_9B : UART_WORDLENGTH_8B; uartPort->Handle.Init.StopBits = (uartPort->port.options & SERIAL_STOPBITS_2) ? USART_STOPBITS_2 : USART_STOPBITS_1; uartPort->Handle.Init.Parity = (uartPort->port.options & SERIAL_PARITY_EVEN) ? USART_PARITY_EVEN : USART_PARITY_NONE; uartPort->Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;