Fix: I2S TDM RX slot_bit_width set to 32BIT to prevent DMA out-of-bounds write - #17
Open
lvips wants to merge 1 commit into
Open
Fix: I2S TDM RX slot_bit_width set to 32BIT to prevent DMA out-of-bounds write#17lvips wants to merge 1 commit into
lvips wants to merge 1 commit into
Conversation
根因: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 (宏名拼写纠正)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: I2S TDM RX slot_bit_width set to 32BIT to prevent DMA out-of-bounds write
Problem / 问题
On M5Stack Tab5, using the ES7210 codec in TDM mode for 4-microphone input causes a DMA out-of-bounds write that corrupts adjacent heap blocks, ultimately triggering
CORRUPT HEAPpanic and speaker popping/clicking noise.在 M5Stack Tab5 上,ES7210 codec 以 TDM 模式采集 4 路麦克风时,会发生 DMA 越界写,腐蚀相邻 heap block,最终触发
CORRUPT HEAPpanic 并伴随扬声器哒哒哒杂音。Root Cause / 根因
The ES7210 outputs 32 bits per TDM slot, but the I2S RX channel was configured with
slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO. ESP-IDF's auto-detection misinterprets this as 16-bit × 2-slot, causing the DMA intermediate buffer to be written with 86–588 extra bytes beyond its allocated size, overwriting the neighboring heap block.ES7210 TDM 4mic 实际按 32bit/slot 输出,但 I2S RX 配置
slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO被 ESP-IDF 误判为 16bit×2slot,DMA 中间 buffer 被多写入 86~588 字节,踩坏相邻 heap block。Fix / 修复
In
platforms/tab5/components/m5stack_tab5/m5stack_tab5.c, functionbsp_audio_init():slot_bit_widthI2S_SLOT_BIT_WIDTH_AUTOI2S_SLOT_BIT_WIDTH_32BITws_widthI2S_TDM_AUTO_WS_WIDTH16dma_desc_num6dma_frame_num480256mic_selectedES7120_SEL_MIC1..4ES7210_SEL_MIC1..4Code Diff / 代码差异
Impact & Verification / 影响与验证
Tested on: M5Stack Tab5 with ES7210 4-mic TDM input
Before fix:
CORRUPT HEAPpanic after minutes of audio capture; speaker clickingAfter fix: Stable operation for extended periods, no heap corruption, clean audio
Risk: Low — only affects Tab5 BSP audio init path; no API changes
实测平台: M5Stack Tab5 + ES7210 4mic TDM
修复前: 采集几分钟后 CORRUPT HEAP panic,扬声器哒哒哒
修复后: 长时间稳定运行,无堆腐蚀,音频干净
风险: 低 — 仅影响 Tab5 BSP 音频初始化路径,无 API 变更
Checklist