Skip to content

Commit 05cc2e1

Browse files
helo9MaureenHelm
authored andcommitted
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 <[email protected]>
1 parent c065b0f commit 05cc2e1

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

drivers/serial/uart_stm32.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,18 @@ static int uart_stm32_init(const struct device *dev)
16391639
}
16401640
#endif
16411641

1642+
#ifdef LL_USART_RXPIN_LEVEL_INVERTED
1643+
if (config->rx_invert) {
1644+
LL_USART_SetRXPinLevel(config->usart, LL_USART_RXPIN_LEVEL_INVERTED);
1645+
}
1646+
#endif
1647+
1648+
#ifdef LL_USART_TXPIN_LEVEL_INVERTED
1649+
if (config->tx_invert) {
1650+
LL_USART_SetTXPinLevel(config->usart, LL_USART_TXPIN_LEVEL_INVERTED);
1651+
}
1652+
#endif
1653+
16421654
LL_USART_Enable(config->usart);
16431655

16441656
#ifdef USART_ISR_TEACK
@@ -1751,6 +1763,8 @@ static const struct uart_stm32_config uart_stm32_cfg_##index = { \
17511763
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
17521764
.single_wire = DT_INST_PROP_OR(index, single_wire, false), \
17531765
.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false), \
1766+
.rx_invert = DT_INST_PROP(index, rx_invert), \
1767+
.tx_invert = DT_INST_PROP(index, tx_invert), \
17541768
STM32_UART_IRQ_HANDLER_FUNC(index) \
17551769
}; \
17561770
\

drivers/serial/uart_stm32.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ struct uart_stm32_config {
3232
bool single_wire;
3333
/* enable tx/rx pin swap */
3434
bool tx_rx_swap;
35+
/* enable rx pin inversion */
36+
bool rx_invert;
37+
/* enable tx pin inversion */
38+
bool tx_invert;
3539
const struct pinctrl_dev_config *pcfg;
3640
#if defined(CONFIG_UART_INTERRUPT_DRIVEN) || defined(CONFIG_UART_ASYNC_API) || \
3741
defined(CONFIG_PM)

dts/bindings/serial/st,stm32-lpuart.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ properties:
1414
clocks:
1515
required: true
1616

17+
tx-invert:
18+
type: boolean
19+
required: false
20+
description: |
21+
Invert the binary logic of tx pin. When enabled, physical logic levels are inverted and
22+
we use 1=Low, 0=High instead of 1=High, 0=Low.
23+
24+
rx-invert:
25+
type: boolean
26+
required: false
27+
description: |
28+
Invert the binary logic of rx pin. When enabled, physical logic levels are inverted and
29+
we use 1=Low, 0=High instead of 1=High, 0=Low.
30+
1731
pinctrl-0:
1832
required: true
1933

dts/bindings/serial/st,stm32-uart.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ properties:
2020
only TX pin is used afterwards and should be configured.
2121
RX/TX conflicts must be handled on user side.
2222
23+
tx-invert:
24+
type: boolean
25+
required: false
26+
description: |
27+
Invert the binary logic of tx pin. When enabled, physical logic levels are inverted and
28+
we use 1=Low, 0=High instead of 1=High, 0=Low.
29+
30+
rx-invert:
31+
type: boolean
32+
required: false
33+
description: |
34+
Invert the binary logic of rx pin. When enabled, physical logic levels are inverted and
35+
we use 1=Low, 0=High instead of 1=High, 0=Low.
36+
2337
pinctrl-0:
2438
required: true
2539

dts/bindings/serial/st,stm32-usart.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ properties:
2626
description: |
2727
Swap the TX and RX pins. Used in case of a cross-wired connection.
2828
29+
tx-invert:
30+
type: boolean
31+
required: false
32+
description: |
33+
Invert the binary logic of tx pin. When enabled, physical logic levels are inverted and
34+
we use 1=Low, 0=High instead of 1=High, 0=Low.
35+
36+
rx-invert:
37+
type: boolean
38+
required: false
39+
description: |
40+
Invert the binary logic of rx pin. When enabled, physical logic levels are inverted and
41+
we use 1=Low, 0=High instead of 1=High, 0=Low.
42+
2943
pinctrl-0:
3044
required: true
3145

0 commit comments

Comments
 (0)