Merge pull request #4382 from Sunwancn/stm32-usart-8bits-parity

[drv_usart.c]修复stm32串口开启奇偶校验时字长设置错误
This commit is contained in:
Bernard Xiong 2021-02-26 00:10:14 +08:00 committed by GitHub
commit 8afee3092a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -114,7 +114,10 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
switch (cfg->data_bits) switch (cfg->data_bits)
{ {
case DATA_BITS_8: case DATA_BITS_8:
uart->handle.Init.WordLength = UART_WORDLENGTH_8B; if (cfg->parity == PARITY_ODD || cfg->parity == PARITY_EVEN)
uart->handle.Init.WordLength = UART_WORDLENGTH_9B;
else
uart->handle.Init.WordLength = UART_WORDLENGTH_8B;
break; break;
case DATA_BITS_9: case DATA_BITS_9:
uart->handle.Init.WordLength = UART_WORDLENGTH_9B; uart->handle.Init.WordLength = UART_WORDLENGTH_9B;