drivers: serial: add pin inversion to stm32 u(s)art

Additional properties are added to stm32 u(s)art to allow
for signal inversion.

Signed-off-by: Jonathan Hahn <Jonathan.Hahn@t-online.de>
This commit is contained in:
Jonathan Hahn 2022-04-25 20:12:25 +02:00 committed by Maureen Helm
commit 05cc2e1ac3
5 changed files with 60 additions and 0 deletions

View file

@ -1639,6 +1639,18 @@ static int uart_stm32_init(const struct device *dev)
}
#endif
#ifdef LL_USART_RXPIN_LEVEL_INVERTED
if (config->rx_invert) {
LL_USART_SetRXPinLevel(config->usart, LL_USART_RXPIN_LEVEL_INVERTED);
}
#endif
#ifdef LL_USART_TXPIN_LEVEL_INVERTED
if (config->tx_invert) {
LL_USART_SetTXPinLevel(config->usart, LL_USART_TXPIN_LEVEL_INVERTED);
}
#endif
LL_USART_Enable(config->usart);
#ifdef USART_ISR_TEACK
@ -1751,6 +1763,8 @@ static const struct uart_stm32_config uart_stm32_cfg_##index = { \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
.single_wire = DT_INST_PROP_OR(index, single_wire, false), \
.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false), \
.rx_invert = DT_INST_PROP(index, rx_invert), \
.tx_invert = DT_INST_PROP(index, tx_invert), \
STM32_UART_IRQ_HANDLER_FUNC(index) \
}; \
\

View file

@ -32,6 +32,10 @@ struct uart_stm32_config {
bool single_wire;
/* enable tx/rx pin swap */
bool tx_rx_swap;
/* enable rx pin inversion */
bool rx_invert;
/* enable tx pin inversion */
bool tx_invert;
const struct pinctrl_dev_config *pcfg;
#if defined(CONFIG_UART_INTERRUPT_DRIVEN) || defined(CONFIG_UART_ASYNC_API) || \
defined(CONFIG_PM)

View file

@ -14,6 +14,20 @@ properties:
clocks:
required: true
tx-invert:
type: boolean
required: false
description: |
Invert the binary logic of tx pin. When enabled, physical logic levels are inverted and
we use 1=Low, 0=High instead of 1=High, 0=Low.
rx-invert:
type: boolean
required: false
description: |
Invert the binary logic of rx pin. When enabled, physical logic levels are inverted and
we use 1=Low, 0=High instead of 1=High, 0=Low.
pinctrl-0:
required: true

View file

@ -20,6 +20,20 @@ properties:
only TX pin is used afterwards and should be configured.
RX/TX conflicts must be handled on user side.
tx-invert:
type: boolean
required: false
description: |
Invert the binary logic of tx pin. When enabled, physical logic levels are inverted and
we use 1=Low, 0=High instead of 1=High, 0=Low.
rx-invert:
type: boolean
required: false
description: |
Invert the binary logic of rx pin. When enabled, physical logic levels are inverted and
we use 1=Low, 0=High instead of 1=High, 0=Low.
pinctrl-0:
required: true

View file

@ -26,6 +26,20 @@ properties:
description: |
Swap the TX and RX pins. Used in case of a cross-wired connection.
tx-invert:
type: boolean
required: false
description: |
Invert the binary logic of tx pin. When enabled, physical logic levels are inverted and
we use 1=Low, 0=High instead of 1=High, 0=Low.
rx-invert:
type: boolean
required: false
description: |
Invert the binary logic of rx pin. When enabled, physical logic levels are inverted and
we use 1=Low, 0=High instead of 1=High, 0=Low.
pinctrl-0:
required: true