diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index 433ad326355..c89ea4c02be 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -1585,6 +1585,11 @@ static int uart_stm32_init(const struct device *dev) /* Set the default baudrate */ uart_stm32_set_baudrate(dev, data->baud_rate); + /* Enable the single wire / half-duplex mode */ + if (config->single_wire) { + LL_USART_EnableHalfDuplex(UartInstance); + } + LL_USART_Enable(UartInstance); #ifdef USART_ISR_TEACK @@ -1701,6 +1706,7 @@ static const struct uart_stm32_config uart_stm32_cfg_##index = { \ .hw_flow_control = DT_INST_PROP(index, hw_flow_control), \ .parity = DT_INST_ENUM_IDX_OR(index, parity, UART_CFG_PARITY_NONE), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \ + .single_wire = DT_INST_PROP_OR(index, single_wire, false), \ STM32_UART_POLL_IRQ_HANDLER_FUNC(index) \ }; \ \ diff --git a/drivers/serial/uart_stm32.h b/drivers/serial/uart_stm32.h index d5e6e86eb02..4f242a8519a 100644 --- a/drivers/serial/uart_stm32.h +++ b/drivers/serial/uart_stm32.h @@ -23,6 +23,8 @@ struct uart_stm32_config { bool hw_flow_control; /* initial parity, 0 for none, 1 for odd, 2 for even */ int parity; + /* switch to enable single wire / half duplex feature */ + bool single_wire; const struct pinctrl_dev_config *pcfg; #if defined(CONFIG_PM) \ && !defined(CONFIG_UART_INTERRUPT_DRIVEN) \ diff --git a/dts/bindings/serial/st,stm32-uart.yaml b/dts/bindings/serial/st,stm32-uart.yaml index 6dba4704429..2369e2ac201 100644 --- a/dts/bindings/serial/st,stm32-uart.yaml +++ b/dts/bindings/serial/st,stm32-uart.yaml @@ -11,6 +11,15 @@ properties: interrupts: required: true + single-wire: + type: boolean + required: false + description: | + Enable the single wire half-duplex communication. + Using this mode, TX and RX lines are internally connected and + only TX pin is used afterwards and should be configured. + RX/TX conflicts must be handled on user side. + pinctrl-0: required: true diff --git a/dts/bindings/serial/st,stm32-usart.yaml b/dts/bindings/serial/st,stm32-usart.yaml index 8d82a827159..44044c9e892 100644 --- a/dts/bindings/serial/st,stm32-usart.yaml +++ b/dts/bindings/serial/st,stm32-usart.yaml @@ -11,6 +11,15 @@ properties: interrupts: required: true + single-wire: + type: boolean + required: false + description: | + Enable the single wire half-duplex communication. + Using this mode, TX and RX lines are internally connected and + only TX pin is used afterwards and should be configured. + RX/TX conflicts must be handled on user side. + pinctrl-0: required: true