Skip to content

Commit 8b96dff

Browse files
nordic-krchaescolar
authored andcommitted
drivers: serial: nrfx_uarte2: Fix error event not being sent
When RX length was 0 and error was reported then UART_RX_STOPPED event was not sent. Fixing the condition check to ensure that UART_RX_STOPPED is always generated. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 5a41aa2 commit 8b96dff

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

drivers/serial/uart_nrfx_uarte2.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,23 +242,22 @@ static void on_rx_done(const struct device *dev, const nrfx_uarte_event_t *event
242242
struct uarte_nrfx_data *data = dev->data;
243243
struct uart_event evt;
244244

245-
if (event->data.rx.length) {
246-
if (data->async->err) {
247-
evt.type = UART_RX_STOPPED;
248-
evt.data.rx_stop.reason = UARTE_ERROR_FROM_MASK(data->async->err);
249-
evt.data.rx_stop.data.buf = event->data.rx.p_buffer;
250-
evt.data.rx_stop.data.len = event->data.rx.length;
251-
/* Keep error code for uart_err_check(). */
252-
if (!IS_INT_DRIVEN_API(dev)) {
253-
data->async->err = 0;
254-
}
255-
} else {
256-
evt.type = UART_RX_RDY,
257-
evt.data.rx.buf = event->data.rx.p_buffer,
258-
evt.data.rx.len = event->data.rx.length,
259-
evt.data.rx.offset = 0;
245+
if (data->async->err) {
246+
evt.type = UART_RX_STOPPED;
247+
evt.data.rx_stop.reason = UARTE_ERROR_FROM_MASK(data->async->err);
248+
evt.data.rx_stop.data.buf = event->data.rx.p_buffer;
249+
evt.data.rx_stop.data.len = event->data.rx.length;
250+
/* Keep error code for uart_err_check(). */
251+
if (!IS_INT_DRIVEN_API(dev)) {
252+
data->async->err = 0;
260253
}
261254
data->async->user_callback(dev, &evt, data->async->user_data);
255+
} else if (event->data.rx.length) {
256+
evt.type = UART_RX_RDY,
257+
evt.data.rx.buf = event->data.rx.p_buffer,
258+
evt.data.rx.len = event->data.rx.length,
259+
evt.data.rx.offset = 0;
260+
data->async->user_callback(dev, &evt, data->async->user_data);
262261
}
263262

264263
evt.type = UART_RX_BUF_RELEASED;

0 commit comments

Comments
 (0)