Skip to content

Commit 166d5f1

Browse files
houwenxiangespressif-bot
authored andcommitted
driver(I2S): Fix I2S reset issue
`i2s_start` reseting I2S in incorrect order causeing the word-order error. closes espressif/esp-idf#5410
1 parent 5d970c0 commit 166d5f1

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

components/driver/i2s.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,6 @@ static int _i2s_adc_channel = -1;
107107
static i2s_dma_t *i2s_create_dma_queue(i2s_port_t i2s_num, int dma_buf_count, int dma_buf_len);
108108
static esp_err_t i2s_destroy_dma_queue(i2s_port_t i2s_num, i2s_dma_t *dma);
109109

110-
static esp_err_t i2s_reset_fifo(i2s_port_t i2s_num)
111-
{
112-
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
113-
I2S_ENTER_CRITICAL();
114-
i2s_hal_reset_fifo(&(p_i2s_obj[i2s_num]->hal));
115-
I2S_EXIT_CRITICAL();
116-
return ESP_OK;
117-
}
118-
119110
static inline void gpio_matrix_out_check(uint32_t gpio, uint32_t signal_idx, bool out_inv, bool oen_inv)
120111
{
121112
//if pin = -1, do not need to configure
@@ -469,6 +460,14 @@ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t b
469460
ESP_LOGI(I2S_TAG, "PLL_D2: Req RATE: %d, real rate: %0.3f, BITS: %u, CLKM: %u, BCK: %u, MCLK: %0.3f, SCLK: %f, diva: %d, divb: %d",
470461
rate, real_rate, bits, clkmInteger, bck, (double)I2S_BASE_CLK / mclk, real_rate*bits*channel, 64, clkmDecimals);
471462
}
463+
if (p_i2s_obj[i2s_num]->mode & I2S_MODE_TX) {
464+
p_i2s_obj[i2s_num]->tx->curr_ptr = NULL;
465+
p_i2s_obj[i2s_num]->tx->rw_pos = 0;
466+
}
467+
if (p_i2s_obj[i2s_num]->mode & I2S_MODE_RX) {
468+
p_i2s_obj[i2s_num]->rx->curr_ptr = NULL;
469+
p_i2s_obj[i2s_num]->rx->rw_pos = 0;
470+
}
472471

473472
i2s_hal_set_tx_bits_mod(&(p_i2s_obj[i2s_num]->hal), bits);
474473
i2s_hal_set_rx_bits_mod(&(p_i2s_obj[i2s_num]->hal), bits);
@@ -643,9 +642,7 @@ static i2s_dma_t *i2s_create_dma_queue(i2s_port_t i2s_num, int dma_buf_count, in
643642
}
644643
dma->queue = xQueueCreate(dma_buf_count - 1, sizeof(char*));
645644
dma->mux = xSemaphoreCreateMutex();
646-
dma->rw_pos = 0;
647645
dma->buf_size = dma_buf_len * sample_size;
648-
dma->curr_ptr = NULL;
649646
ESP_LOGI(I2S_TAG, "DMA Malloc info, datalen=blocksize=%d, dma_buf_count=%d", dma_buf_len * sample_size, dma_buf_count);
650647
return dma;
651648
}
@@ -655,8 +652,6 @@ esp_err_t i2s_start(i2s_port_t i2s_num)
655652
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
656653
//start DMA link
657654
I2S_ENTER_CRITICAL();
658-
i2s_reset_fifo(i2s_num);
659-
660655
i2s_hal_reset(&(p_i2s_obj[i2s_num]->hal));
661656

662657
esp_intr_disable(p_i2s_obj[i2s_num]->i2s_isr_handle);
@@ -865,7 +860,6 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
865860
}
866861
#endif
867862
// configure I2S data port interface.
868-
i2s_reset_fifo(i2s_num);
869863
i2s_hal_config_param(&(p_i2s_obj[i2s_num]->hal), i2s_config);
870864
if ((p_i2s_obj[i2s_num]->mode & I2S_MODE_RX) && (p_i2s_obj[i2s_num]->mode & I2S_MODE_TX)) {
871865
i2s_hal_enable_sig_loopback(&(p_i2s_obj[i2s_num]->hal));

components/soc/include/hal/i2s_hal.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ typedef struct {
4040
uint32_t version;
4141
} i2s_hal_context_t;
4242

43-
/**
44-
* @brief Reset I2S fifo
45-
*
46-
* @param hal Context of the HAL layer
47-
*/
48-
void i2s_hal_reset_fifo(i2s_hal_context_t *hal);
49-
5043
/**
5144
* @brief Get I2S interrupt status
5245
*
@@ -214,7 +207,7 @@ void i2s_hal_set_tx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits)
214207
void i2s_hal_set_rx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits);
215208

216209
/**
217-
* @brief Reset I2S tx
210+
* @brief Reset I2S TX & RX module, including DMA and FIFO
218211
*
219212
* @param hal Context of the HAL layer
220213
*/

components/soc/src/hal/i2s_hal.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
#include "soc/soc.h"
1818
#include "hal/i2s_hal.h"
1919

20-
void i2s_hal_reset_fifo(i2s_hal_context_t *hal)
21-
{
22-
i2s_ll_reset_rx_fifo(hal->dev);
23-
i2s_ll_reset_tx_fifo(hal->dev);
24-
}
25-
2620
void i2s_hal_set_tx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits)
2721
{
2822
if (bits <= I2S_BITS_PER_SAMPLE_16BIT) {
@@ -84,10 +78,13 @@ void i2s_hal_set_rx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits)
8478

8579
void i2s_hal_reset(i2s_hal_context_t *hal)
8680
{
87-
i2s_ll_reset_dma_in(hal->dev);
88-
i2s_ll_reset_dma_out(hal->dev);
81+
// Reset I2S TX/RX module first, and then, reset DMA and FIFO.
8982
i2s_ll_reset_tx(hal->dev);
9083
i2s_ll_reset_rx(hal->dev);
84+
i2s_ll_reset_dma_in(hal->dev);
85+
i2s_ll_reset_dma_out(hal->dev);
86+
i2s_ll_reset_rx_fifo(hal->dev);
87+
i2s_ll_reset_tx_fifo(hal->dev);
9188
}
9289

9390
void i2s_hal_start_tx(i2s_hal_context_t *hal)

0 commit comments

Comments
 (0)