drivers: serial: stm32: Support for parity in DTS for STM32 uart.

Add support for devicetree property 'parity' for stm32 serial devices.

Signed-off-by: Pauli Salmenrinne <susundberg@gmail.com>
This commit is contained in:
Pauli Salmenrinne 2020-03-18 13:40:21 +02:00 committed by Kumar Gala
commit 30003ffb86
5 changed files with 48 additions and 4 deletions

View file

@ -661,6 +661,8 @@ static int uart_stm32_init(struct device *dev)
const struct uart_stm32_config *config = DEV_CFG(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
USART_TypeDef *UartInstance = UART_STRUCT(dev);
u32_t ll_parity;
u32_t ll_datawidth;
__uart_stm32_get_clock(dev);
/* enable clock */
@ -675,10 +677,31 @@ static int uart_stm32_init(struct device *dev)
LL_USART_SetTransferDirection(UartInstance,
LL_USART_DIRECTION_TX_RX);
/* 8 data bit, 1 start bit, 1 stop bit, no parity */
/* Determine the datawidth and parity. If we use other parity than
* 'none' we must use datawidth = 9 (to get 8 databit + 1 parity bit).
*/
if (config->parity == 2) {
/* 8 databit, 1 parity bit, parity even */
ll_parity = LL_USART_PARITY_EVEN;
ll_datawidth = LL_USART_DATAWIDTH_9B;
} else if (config->parity == 1) {
/* 8 databit, 1 parity bit, parity odd */
ll_parity = LL_USART_PARITY_ODD;
ll_datawidth = LL_USART_DATAWIDTH_9B;
} else { /* Default to 8N0, but show warning if invalid value */
if (config->parity != 0) {
LOG_WRN("Invalid parity setting '%d'."
"Defaulting to 'none'.", config->parity);
}
/* 8 databit, parity none */
ll_parity = LL_USART_PARITY_NONE;
ll_datawidth = LL_USART_DATAWIDTH_8B;
}
/* Set datawidth and parity, 1 start bit, 1 stop bit */
LL_USART_ConfigCharacter(UartInstance,
LL_USART_DATAWIDTH_8B,
LL_USART_PARITY_NONE,
ll_datawidth,
ll_parity,
LL_USART_STOPBITS_1);
if (config->hw_flow_control) {
@ -740,7 +763,8 @@ static const struct uart_stm32_config uart_stm32_cfg_##index = { \
.pclken = { .bus = DT_INST_CLOCKS_CELL(index, bus), \
.enr = DT_INST_CLOCKS_CELL(index, bits) \
}, \
.hw_flow_control = DT_INST_PROP(index, hw_flow_control)\
.hw_flow_control = DT_INST_PROP(index, hw_flow_control),\
.parity = DT_INST_PROP(index, parity)\
}; \
\
static struct uart_stm32_data uart_stm32_data_##index = { \

View file

@ -19,6 +19,8 @@ struct uart_stm32_config {
struct stm32_pclken pclken;
/* initial hardware flow control, 1 for RTS/CTS */
bool hw_flow_control;
/* initial parity, 0 for none, 1 for odd, 2 for even */
int parity;
};
/* driver data */

View file

@ -13,3 +13,9 @@ properties:
clocks:
required: true
parity:
required: false
type: int
description: Configures the parity of the adapter. Value 0 for none, 1 for odd and 2 for even parity.
default: 0

View file

@ -10,3 +10,9 @@ properties:
interrupts:
required: true
parity:
required: false
type: int
description: Configures the parity of the adapter. Value 0 for none, 1 for odd and 2 for even parity.
default: 0

View file

@ -10,3 +10,9 @@ properties:
interrupts:
required: true
parity:
required: false
type: int
description: Configures the parity of the adapter. Value 0 for none, 1 for odd and 2 for even parity.
default: 0