From f681d8976e45b7e11ec4f2672e193969a2f8754f Mon Sep 17 00:00:00 2001 From: Hu Rui Date: Wed, 8 Jul 2026 17:08:08 +0800 Subject: [PATCH] fix(uhci): rx fsm race condition Closes https://github.com/espressif/esp-idf/issues/18746 --- components/esp_driver_uart/src/uhci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/esp_driver_uart/src/uhci.c b/components/esp_driver_uart/src/uhci.c index 35318be6efd..4c4142bd73c 100644 --- a/components/esp_driver_uart/src/uhci.c +++ b/components/esp_driver_uart/src/uhci.c @@ -164,7 +164,7 @@ static bool uhci_gdma_rx_callback_done(gdma_channel_handle_t dma_chan, gdma_even gdma_stop(uhci_ctrl->rx_dir.dma_chan); gdma_reset(uhci_ctrl->rx_dir.dma_chan); - uhci_ctrl->rx_dir.rx_fsm = UHCI_RX_FSM_ENABLE; + atomic_store(&uhci_ctrl->rx_dir.rx_fsm, UHCI_RX_FSM_ENABLE); } if (event_data->flags.abnormal_eof) { @@ -363,10 +363,11 @@ esp_err_t uhci_receive(uhci_controller_handle_t uhci_ctrl, uint8_t *read_buffer, ESP_RETURN_ON_ERROR(esp_cache_msync(mount_configs[0].buffer, usable_size, ESP_CACHE_MSYNC_FLAG_DIR_M2C), TAG, "cache sync failed"); } + atomic_store(&uhci_ctrl->rx_dir.rx_fsm, UHCI_RX_FSM_RUN); + gdma_reset(uhci_ctrl->rx_dir.dma_chan); gdma_start(uhci_ctrl->rx_dir.dma_chan, gdma_link_get_head_addr(uhci_ctrl->rx_dir.dma_link)); - atomic_store(&uhci_ctrl->rx_dir.rx_fsm, UHCI_RX_FSM_RUN); return ESP_OK; }