4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-30 06:00:27 +08:00

[drv_usart.c]修复stm32串口开启奇偶校验时字长设置错误

This commit is contained in:
Sunwancn 2021-02-24 21:11:27 +08:00
parent 2cbb9c5388
commit e22f72293e

View File

@ -112,7 +112,10 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
switch (cfg->data_bits)
{
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;
case DATA_BITS_9:
uart->handle.Init.WordLength = UART_WORDLENGTH_9B;