From 19e60a43dd2c37415d72d4a5ac2a65b2264da1ef Mon Sep 17 00:00:00 2001 From: lvips Date: Sun, 23 Aug 2026 18:38:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(audio):=20I2S=20TDM=20RX=20slot=5Fbit=5Fwid?= =?UTF-8?q?th=20=E6=94=B9=2032BIT=20=E9=98=B2=20DMA=20=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:ES7210 TDM 4mic 实际按 32bit/slot 输出,但 I2S RX 配 slot_bit_width=AUTO 被 ESP-IDF 误判为 16bit×2slot,DMA 中间 buffer 被多写入 86~588 字节踩坏相邻 heap block,触发 CORRUPT HEAP → panic → 扬声器哒哒哒。 修复 (m5stack_tab5.c bsp_audio_init): - slot_bit_width: AUTO → I2S_SLOT_BIT_WIDTH_32BIT - ws_width: AUTO → 16 (消除版本歧义) - dma_frame_num: 480 → 256 (对齐 64B 边界,消除 auto-adjust 警告) - ES7120_SEL_MIC → ES7210_SEL_MIC (宏名拼写纠正) --- platforms/tab5/components/m5stack_tab5/m5stack_tab5.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/platforms/tab5/components/m5stack_tab5/m5stack_tab5.c b/platforms/tab5/components/m5stack_tab5/m5stack_tab5.c index 1621253b..30d5defa 100644 --- a/platforms/tab5/components/m5stack_tab5/m5stack_tab5.c +++ b/platforms/tab5/components/m5stack_tab5/m5stack_tab5.c @@ -723,6 +723,11 @@ esp_err_t bsp_audio_init(const i2s_std_config_t* i2s_config) /* Setup I2S peripheral */ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(CONFIG_BSP_I2S_NUM, I2S_ROLE_MASTER); chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer + /* Bump DMA buffers: audio_input reads 960 frames (1920 bytes mono 16-bit) per call. + * Default 256*3 = 1536 bytes is too small and can heap-corrupt on overrun. + * 480 frames/desc * 6 descs * 2 bytes = 5760 bytes total — plenty of headroom. */ + chan_cfg.dma_desc_num = 6; + chan_cfg.dma_frame_num = 256; // ★ fix(heap-corrupt): 直接设 256 对齐 ESP-IDF DMA buffer 64 字节对齐要求,避免 auto-adjust 警告 ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &i2s_tx_chan, &i2s_rx_chan)); /* Setup I2S channels */ @@ -753,10 +758,10 @@ esp_err_t bsp_audio_init(const i2s_std_config_t* i2s_config) .bclk_div = 8, }, .slot_cfg = {.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT, - .slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, + .slot_bit_width = I2S_SLOT_BIT_WIDTH_32BIT, // ★ fix(heap-corrupt): 匹配 ES7210 TDM 4mic 实际输出 32bit/slot,避免 DMA 越界写 .slot_mode = I2S_SLOT_MODE_STEREO, .slot_mask = (I2S_TDM_SLOT0 | I2S_TDM_SLOT1 | I2S_TDM_SLOT2 | I2S_TDM_SLOT3), - .ws_width = I2S_TDM_AUTO_WS_WIDTH, + .ws_width = 16, // ★ fix(heap-corrupt): 显式设 16 替代 AUTO,消除版本歧义 .ws_pol = false, .bit_shift = true, .left_align = false, @@ -856,7 +861,7 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void) es7210_codec_cfg_t es7210_cfg = { .ctrl_if = i2c_ctrl_if, // Codec Control interface }; - es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3 | ES7120_SEL_MIC4; + es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3 | ES7210_SEL_MIC4; const audio_codec_if_t* es7210_dev = es7210_codec_new(&es7210_cfg); BSP_NULL_CHECK(es7210_dev, NULL);