esp-idf: Unable to set I2S APLL Clock for 48khz 32bit 2ch (IDFGH-432)
Environment
- Core (if using chip or module): ESP-WROOM32
- IDF version 7c29a39d6
- Development Env: Eclipse
- Operating System: MacOS
- Power Supply: external 3.3V
Problem Description
In I2S Slave TX mode
i2s_mode_t mode = I2S_MODE_SLAVE | I2S_MODE_TX; i2s_comm_format_t comm_fmt = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB;
If I set a frequency of 48Khz and APLL, it will not set the frequency correctly and I got audio problems, I imagine is because of DMA buffer under/overrun.
I (352) phy: phy_version: 4000, b6198fa, Sep 3 2018, 15:11:06, 0, 2 I (902) I2S: queue free spaces: 1 I (912) I2S: DMA Malloc info, datalen=blocksize=4088, dma_buf_count=16 I (912) I2S: APLL: Req RATE: 48000, real rate: 43945.238, BITS: 32, CLKM: 1, BCK_M: 8, MCLK: 22499962.000, SCLK: 2812495.250000, diva: 1, divb: 0 I (932) BT_APP_CORE: bt_app_task_handler, sig 0x1, 0x0 I (932) main: RAM left 75544
If I disable APLL, then the frequency is correctly set - but I get crappy sound due to fractional PLL.
In case I set mclk_fixed (at 24573600.000) I get 50Khz:
I (781) I2S: queue free spaces: 1 I (781) I2S: DMA Malloc info, datalen=blocksize=4088, dma_buf_count=16 I (791) I2S: APLL: Req RATE: 48000, real rate: 50223.129, BITS: 32, CLKM: 1, BCK_M: 7, MCLK: 22499962.000, SCLK: 2812495.250000, diva: 1, divb: 0 I (801) BT_APP_CORE: bt_app_task_handler, sig 0x1, 0x0 I (811) main: RAM left 75668
I imagine that the problem could be in function i2s_apll_calculate_fi2s
that have a bad behaviour in case of 48Khz 32bit 2ch.
Then further investigation get me through an error in the documentation: APLL_MAX_FREQ = 500Mhz and APLL_MIN_FREQ = 250 Mhz
but in the description of we read:
* The dividend in this expression should be in the range of 240 - 600 MHz.
and
* 1. We will choose the parameters with the highest level of change,
* With 350MHz<fout<500MHz, we limit the sdm2 from 4 to 9,
What’s the trouth?
Steps to reproduce
Take A2DP_Sink Example and set I2S at 48Khz, Slave, 32Bit.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (2 by maintainers)
Commits related to this issue
- fix a bug when calculating i2s apll parameters. fix #2634, #3380 — committed to redchenjs/esp-idf by redchenjs 5 years ago
- fix a bug when calculating i2s apll parameters. fix #2634, #3380 — committed to redchenjs/esp-idf by redchenjs 5 years ago
- i2s: fix a bug when calculating i2s apll parameters Closes https://github.com/espressif/esp-idf/issues/2634 Closes https://github.com/espressif/esp-idf/issues/3380 Fixes https://github.com/espressif/... — committed to espressif/esp-idf by redchenjs 5 years ago
- i2s: fix a bug when calculating i2s apll parameters Closes https://github.com/espressif/esp-idf/issues/2634 Closes https://github.com/espressif/esp-idf/issues/3380 Fixes https://github.com/espressif/... — committed to espressif/esp-idf by redchenjs 5 years ago
- i2s: fix a bug when calculating i2s apll parameters Closes https://github.com/espressif/esp-idf/issues/2634 Closes https://github.com/espressif/esp-idf/issues/3380 Fixes https://github.com/espressif/... — committed to trombik/esp-idf by redchenjs 5 years ago
I think 176k @ 16bits is the maximum that can be done, taking into account various constraints. The code is the follòwing. The sampling rate required is 2x the original sampling rate and sample size is 32 bits. Then the resulting buffer shall be send to a led connected to the SD line of the I2S, that’s all