From 07410a1381a74789766705d313c3c7bd391034cb Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Mon, 6 Sep 2021 13:39:25 +0800 Subject: [PATCH] i2s: fix write failure issue in slave mode --- components/driver/i2s.c | 8 ++++++++ components/hal/include/hal/i2s_types.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/driver/i2s.c b/components/driver/i2s.c index 7c5921a507..ee219cd26f 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -327,6 +327,14 @@ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t b return ESP_ERR_INVALID_ARG; } p_i2s_obj[i2s_num]->sample_rate = rate; + + /** + * Due to hardware issue, bck division on ESP32/ESP32-S2 should be greater than 8 in slave mode + * So the factor need to be an appropriate value + */ + if ((p_i2s_obj[i2s_num]->mode & I2S_MODE_SLAVE) && !p_i2s_obj[i2s_num]->use_apll) { + factor = 64 * bits; + } double clkmdiv = (double)I2S_BASE_CLK / (rate * factor); if (clkmdiv > 256) { diff --git a/components/hal/include/hal/i2s_types.h b/components/hal/include/hal/i2s_types.h index 2b41b1b491..e2c698a562 100644 --- a/components/hal/include/hal/i2s_types.h +++ b/components/hal/include/hal/i2s_types.h @@ -61,7 +61,7 @@ typedef enum { typedef enum { // In order to keep compatibility, remain the old definitions and introduce new definitions, I2S_COMM_FORMAT_STAND_I2S = 0X01, /*!< I2S communication I2S Philips standard, data launch at second BCK*/ - I2S_COMM_FORMAT_STAND_MSB = 0X03, /*!< I2S communication MSB alignment standard, data launch at first BCK*/ + I2S_COMM_FORMAT_STAND_MSB = 0X02, /*!< I2S communication MSB alignment standard, data launch at first BCK*/ I2S_COMM_FORMAT_STAND_PCM_SHORT = 0x04, /*!< PCM Short standard, also known as DSP mode. The period of synchronization signal (WS) is 1 bck cycle.*/ I2S_COMM_FORMAT_STAND_PCM_LONG = 0x0C, /*!< PCM Long standard. The period of synchronization signal (WS) is channel_bit*bck cycles.*/ I2S_COMM_FORMAT_STAND_MAX, /*!< standard max*/