Skip to content

Commit 6b850c9

Browse files
nordic-krchrlubos
authored andcommitted
drivers: serial: lpuart: Improve handling of fault cases
Improve handling of a case when control pins do not follow the protocol behavior (e.g. they are floating). In that case driver should not trigger assert but just return to the off state. Signed-off-by: Krzysztof Chruściński <[email protected]> (cherry picked from commit 31e08fd)
1 parent da6bcc9 commit 6b850c9

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/serial/uart_nrf_sw_lpuart.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,7 @@ static void uart_callback(const struct device *uart, struct uart_event *evt,
588588
bool call_cb;
589589

590590
LOG_DBG("Rx disabled %d", data->rx_state);
591-
__ASSERT_NO_MSG((data->rx_state != RX_IDLE) &&
592-
(data->rx_state != RX_OFF));
591+
__ASSERT_NO_MSG(data->rx_state != RX_OFF);
593592

594593
if (data->rx_state == RX_TO_IDLE) {
595594
if (data->rx_got_data) {
@@ -603,6 +602,25 @@ static void uart_callback(const struct device *uart, struct uart_event *evt,
603602
rdy_pin_idle(data);
604603
}
605604
} else {
605+
if (data->rx_state == RX_IDLE && data->rx_buf) {
606+
/* This case may happen if control pins are not behaving
607+
* according to the protocol (e.g. they are floating).
608+
* In that case driver goes to off state and releases
609+
* provided buffers.
610+
*/
611+
struct uart_event buf_rel_evt = {
612+
.type = UART_RX_BUF_RELEASED,
613+
.data = {
614+
.rx_buf = {
615+
.buf = data->rx_buf
616+
}
617+
}
618+
};
619+
620+
LOG_DBG("RX: Rx buf released %p", (void *)data->rx_buf);
621+
user_callback(dev, &buf_rel_evt);
622+
}
623+
606624
data->rx_buf = NULL;
607625
data->rx_state = RX_OFF;
608626
call_cb = true;

0 commit comments

Comments
 (0)