From 644299e8256da2a9964eea7637237adddd7e744f Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Thu, 24 Apr 2025 15:04:06 +0800 Subject: [PATCH] fix(rmt): fix race condition and add receive config error message Closes https://github.com/espressif/esp-idf/issues/15842 Closes https://github.com/espressif/esp-idf/issues/15836 --- components/driver/rmt/rmt_rx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/driver/rmt/rmt_rx.c b/components/driver/rmt/rmt_rx.c index 0757e45284..c2eeffb5cf 100644 --- a/components/driver/rmt/rmt_rx.c +++ b/components/driver/rmt/rmt_rx.c @@ -374,8 +374,8 @@ esp_err_t rmt_receive(rmt_channel_handle_t channel, void *buffer, size_t buffer_ uint32_t filter_reg_value = ((uint64_t)rx_chan->filter_clock_resolution_hz * config->signal_range_min_ns) / 1000000000UL; uint32_t idle_reg_value = ((uint64_t)channel->resolution_hz * config->signal_range_max_ns) / 1000000000UL; - ESP_RETURN_ON_FALSE_ISR(filter_reg_value <= RMT_LL_MAX_FILTER_VALUE, ESP_ERR_INVALID_ARG, TAG, "signal_range_min_ns too big"); - ESP_RETURN_ON_FALSE_ISR(idle_reg_value <= RMT_LL_MAX_IDLE_VALUE, ESP_ERR_INVALID_ARG, TAG, "signal_range_max_ns too big"); + ESP_RETURN_ON_FALSE_ISR(filter_reg_value <= RMT_LL_MAX_FILTER_VALUE, ESP_ERR_INVALID_ARG, TAG, "signal_range_min_ns too big, should be less than %"PRIu32" ns", (uint32_t)((uint64_t)RMT_LL_MAX_FILTER_VALUE * 1000000000UL / rx_chan->filter_clock_resolution_hz)); + ESP_RETURN_ON_FALSE_ISR(idle_reg_value <= RMT_LL_MAX_IDLE_VALUE, ESP_ERR_INVALID_ARG, TAG, "signal_range_max_ns too big, should be less than %"PRIu32" ns", (uint32_t)((uint64_t)RMT_LL_MAX_IDLE_VALUE * 1000000000UL / channel->resolution_hz)); // check if we're in a proper state to start the receiver rmt_fsm_t expected_fsm = RMT_FSM_ENABLE; @@ -408,11 +408,11 @@ esp_err_t rmt_receive(rmt_channel_handle_t channel, void *buffer, size_t buffer_ rmt_ll_rx_set_idle_thres(hal->regs, channel_id, idle_reg_value); // turn on RMT RX machine rmt_ll_rx_enable(hal->regs, channel_id, true); - portEXIT_CRITICAL_SAFE(&channel->spinlock); // saying we're in running state, this state will last until the receiving is done // i.e., we will switch back to the enable state in the receive done interrupt handler atomic_store(&channel->fsm, RMT_FSM_RUN); + portEXIT_CRITICAL_SAFE(&channel->spinlock); return ESP_OK; }