@@ -58,6 +58,9 @@ struct mcux_lpuart_config {
5858 uint8_t parity ;
5959 bool rs485_de_active_low ;
6060 bool loopback_en ;
61+ bool single_wire ;
62+ bool tx_invert ;
63+ bool rx_invert ;
6164#ifdef CONFIG_UART_MCUX_LPUART_ISR_SUPPORT
6265 void (* irq_config_func )(const struct device * dev );
6366#endif
@@ -1105,8 +1108,30 @@ static int mcux_lpuart_configure_init(const struct device *dev, const struct uar
11051108 /* Set the LPUART into loopback mode */
11061109 config -> base -> CTRL |= LPUART_CTRL_LOOPS_MASK ;
11071110 config -> base -> CTRL &= ~LPUART_CTRL_RSRC_MASK ;
1111+ } else if (config -> single_wire ) {
1112+ /* Enable the single wire / half-duplex mode, only possible when
1113+ * loopback is disabled. We need a critical section to prevent
1114+ * the UART firing an interrupt during mode switch
1115+ */
1116+ unsigned int key = irq_lock ();
1117+
1118+ config -> base -> CTRL |= (LPUART_CTRL_LOOPS_MASK | LPUART_CTRL_RSRC_MASK );
1119+ irq_unlock (key );
1120+ } else {
1121+ #ifdef LPUART_CTRL_TXINV
1122+ /* Only invert TX in full-duplex mode */
1123+ if (config -> tx_invert ) {
1124+ config -> base -> CTRL |= LPUART_CTRL_TXINV (1 );
1125+ }
1126+ #endif
11081127 }
11091128
1129+ #ifdef LPUART_STAT_RXINV
1130+ if (config -> rx_invert ) {
1131+ config -> base -> STAT |= LPUART_STAT_RXINV (1 );
1132+ }
1133+ #endif
1134+
11101135 /* update internal uart_config */
11111136 data -> uart_config = * cfg ;
11121137
@@ -1126,6 +1151,9 @@ static int mcux_lpuart_configure(const struct device *dev,
11261151{
11271152 const struct mcux_lpuart_config * config = dev -> config ;
11281153
1154+ /* Make sure that RSRC is de-asserted otherwise deinit will hang. */
1155+ config -> base -> CTRL &= ~LPUART_CTRL_RSRC_MASK ;
1156+
11291157 /* disable LPUART */
11301158 LPUART_Deinit (config -> base );
11311159
@@ -1330,6 +1358,9 @@ static const struct mcux_lpuart_config mcux_lpuart_##n##_config = { \
13301358 .parity = DT_INST_ENUM_IDX_OR(n, parity, UART_CFG_PARITY_NONE), \
13311359 .rs485_de_active_low = DT_INST_PROP(n, nxp_rs485_de_active_low), \
13321360 .loopback_en = DT_INST_PROP(n, nxp_loopback), \
1361+ .single_wire = DT_INST_PROP(n, single_wire), \
1362+ .rx_invert = DT_INST_PROP(n, rx_invert), \
1363+ .tx_invert = DT_INST_PROP(n, tx_invert), \
13331364 .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
13341365 MCUX_LPUART_IRQ_INIT(n) \
13351366 RX_DMA_CONFIG(n) \
0 commit comments