MCU: MIMXRT685-EVK (i.MX RT685)
Board: Custom product board based on RT685.
I am using Loop DMA mode with ping-pong buffers. The DMA is configured with I2S_TransferSendLoopDMA() using 2 descriptors. In the DMA callback, I fill the next buffer and the loop continues automatically.
void I2S1_TDM_Init(void)
{
I2S_Type *base = I2S1;
/* I2S Configuration */
i2s_config_t cfg;
I2S_TxGetDefaultConfig(&cfg);
cfg.masterSlave = kI2S_MasterSlaveNormalMaster;
cfg.mode = kI2S_ModeDspWsShort; /* TDM = DSP mode */
cfg.divider = 24576000 / (TDM_SAMPLE_RATE * TDM_SLOT_NUM * TDM_SLOT_WIDTH);
cfg.dataLength = TDM_SLOT_WIDTH; /* 32-bit */
cfg.frameLength = TDM_FRAME_LENGTH; /* 256-bit */
cfg.oneChannel = false;
cfg.position = 0;
cfg.wsPol = true; /* DSP A or B */
I2S_TxInit(base, &cfg);
/* Enable 8 slots (Primary + 3 Secondary Channels) */
/* Note: Using 4 channels to cover 8 slots with 32-bit data */
I2S_EnableSecondaryChannel(base, kI2S_SecondaryChannel1, false, 32 * 2);
I2S_EnableSecondaryChannel(base, kI2S_SecondaryChannel2, false, 32 * 4);
I2S_EnableSecondaryChannel(base, kI2S_SecondaryChannel3, false, 32 * 6);
/* DMA Loop Transfer Setup */
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, I2S_TX_DMA_CH);
DMA_SetChannelPriority(DMA0, I2S_TX_DMA_CH, kDMA_ChannelPriority3);
DMA_CreateHandle(&dma_handle, DMA0, I2S_TX_DMA_CH);
I2S_TxTransferCreateHandleDMA(base, &i2s_handle, &dma_handle,
I2S1_Callback, tdm_xfer);
I2S_TransferInstallLoopDMADescriptorMemory(&i2s_handle, tdm_desc, 2);
if (I2S_TransferSendLoopDMA(base, &i2s_handle, &tdm_xfer[0], 2)
!= kStatus_Success) {
while (1); /* Fails if TDM_FRAMES * 8 > DMA_MAX_TRANSFER_COUNT(1024) */
}
}
The slot offset is random across power cycles, not fixed.I also tried disable interrupts before and after the DMA transfer to force synchronization, but slot misalignment still occurs.
Does I2S_TransferSendLoopDMA() guarantee frame-aligned DMA startup on RT685? If not, how to force alignment to WS boundary?
i.MX-RT600