Skip to content

Commit

Permalink
[nrf fromlist] drivers: serial: nrfx_uarte: Add lock to uart_rx_disable
Browse files Browse the repository at this point in the history
Add lock to fix race when uart_rx_disable is interrupted by RXTO
event which lead to driver state corruption.

Upstream PR: zephyrproject-rtos/zephyr#75462

Signed-off-by: Krzysztof Chruściński <[email protected]>
  • Loading branch information
nordic-krch committed Oct 9, 2024
1 parent d562f29 commit 7b7a4e8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/serial/uart_nrfx_uarte.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,20 +1103,26 @@ static int uarte_nrfx_rx_disable(const struct device *dev)
struct uarte_nrfx_data *data = dev->data;
struct uarte_async_rx *rdata = &data->async->rx;
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
int key;

if (rdata->buf == NULL) {
return -EFAULT;
}

k_timer_stop(&rdata->timer);

key = irq_lock();

if (rdata->next_buf != NULL) {
nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX);
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED);
}

k_timer_stop(&rdata->timer);
rdata->enabled = false;
rdata->discard_fifo = true;

nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX);
irq_unlock(key);

return 0;
}
Expand Down

0 comments on commit 7b7a4e8

Please sign in to comment.