Skip to content

Commit 75263f7

Browse files
nordic-krchnordicjm
authored andcommitted
[nrf fromtree] drivers: serial: nrfx_uarte: Add lock to uart_rx_disable
Add lock to fix race when uart_rx_disable is interrupted by RXTO event which lead to driver state corruption. Signed-off-by: Krzysztof Chruściński <[email protected]> (cherry picked from commit 317de0c)
1 parent c541fa9 commit 75263f7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/serial/uart_nrfx_uarte.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,20 +1099,26 @@ static int uarte_nrfx_rx_disable(const struct device *dev)
10991099
struct uarte_nrfx_data *data = dev->data;
11001100
struct uarte_async_rx *async_rx = &data->async->rx;
11011101
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
1102+
int key;
11021103

11031104
if (async_rx->buf == NULL) {
11041105
return -EFAULT;
11051106
}
1107+
1108+
k_timer_stop(&async_rx->timer);
1109+
1110+
key = irq_lock();
1111+
11061112
if (async_rx->next_buf != NULL) {
11071113
nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX);
11081114
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED);
11091115
}
11101116

1111-
k_timer_stop(&async_rx->timer);
11121117
async_rx->enabled = false;
11131118
async_rx->discard_fifo = true;
11141119

11151120
nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX);
1121+
irq_unlock(key);
11161122

11171123
return 0;
11181124
}

0 commit comments

Comments
 (0)