<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SAI EDMA looping problem in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2010610#M32877</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/132425"&gt;@davenadler&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your updated information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I 'm sorry for my later reply.&lt;/P&gt;
&lt;P&gt;I suggest you call&amp;nbsp; PlaybackSine function in SAI_EDMA_callback just like SDK demo did.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;mayliu&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 02:29:35 GMT</pubDate>
    <dc:creator>mayliu1</dc:creator>
    <dc:date>2024-12-10T02:29:35Z</dc:date>
    <item>
      <title>SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2005578#M32791</link>
      <description>&lt;P&gt;I've got a problem making continuous uninterrupted sound using SAI.&lt;BR /&gt;I've created a sine wave in buffers,&amp;nbsp; based on:&lt;BR /&gt;evkmimxrt1024_sai_peripheral/source/playbackSine.c&lt;BR /&gt;I adjusted the buffer size and frequency played so there is no unused&lt;BR /&gt;space at the end of the last buffer so there should be no gaps.&lt;/P&gt;&lt;P&gt;I transmitted over I2S using SAI_TransferSendLoopEDMA per the pingpong example. This is a transmit-only application, sending 48kHz encoding (16-bit, stereo). I get interrupted sound (correct sine frequency except for spaces) rather than the continuous sound I'm expecting (attached). Note the interruption period is not constant; varies a bit.&lt;/P&gt;&lt;P&gt;Any idea what is going on?&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Best Regards, Dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 02:40:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2005578#M32791</guid>
      <dc:creator>davenadler</dc:creator>
      <dc:date>2024-12-03T02:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2006001#M32801</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/132425"&gt;@davenadler&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thank you so much for your interest in our products and for using our community.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I saw your information that you adjusted the buffer size and frequency.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So please check next points:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1: SAI_TransferSendLoopEDMA&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;Configuration: I think you need to make sure that the parameters you provided to&lt;SPAN&gt; SAI_TransferSendLoopEDMA&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;are correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2: SAI Configuration: The SAI configuration must match your audio data format, For example, the sampling rate, bit depth, number of channels, etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, I think&amp;nbsp; EDMA Transfers should not be interrupted, please check whether it&amp;nbsp; being interrupted by other interrupts or tasks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wish it helps you.&lt;BR /&gt;If you still have question about it, please kindly let me know.&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;mayliu&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 10:32:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2006001#M32801</guid>
      <dc:creator>mayliu1</dc:creator>
      <dc:date>2024-12-03T10:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2006433#M32808</link>
      <description>&lt;P&gt;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/239163"&gt;@mayliu1&lt;/a&gt;- Of course I have already checked these things.&lt;BR /&gt;Much of the configuration must be OK as the correct 600Hz tone is generated.&lt;BR /&gt;But, why is it interrupted?&lt;/P&gt;&lt;P&gt;I've included the code and a dump of the SAI configuration below.&lt;BR /&gt;Much appreciated if anyone can spot what's wrong!&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Best Regards, Dave&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/*
 * audio.cpp - Transmit audio, using SAI1 peripheral TX0 to transmit I2S data
 *
 * Based on:
 *  - evkmimxrt1024_sai_peripheral/source/playbackSine.c
 *  - evkmimxrt1024_sai_edma_ping_pong_buffer\source\sai_edma_ping_pong_buffer.c
 */

#include &amp;lt;stdio.h&amp;gt; // printf, debug only...

#include "board.h"
#include "fsl_dmamux.h"
#include "fsl_edma.h"
#include "fsl_sai_edma.h"

#include "arm_math.h" // CMSIS DSP library

#include "FreeRTOS.h"
#include "task.h"

#include "VarioDMAassignments.hpp"

/*******************************************************************************
 * Variables
 ******************************************************************************/
static edma_handle_t g_dmaHandle;
static sai_edma_handle_t txHandle;
static sai_transceiver_t saiConfig;

#define BUFFER_NUM       (8)
#define BUFFER_SIZE      (512 - (256/BUFFER_NUM)) // 480: shorten buffer slightly so there's no unused space for 600Hz sinewave
AT_NONCACHEABLE_SECTION_ALIGN(static uint8_t audioBuff[(BUFFER_SIZE * BUFFER_NUM)+16], 4);
static uint32_t buffersToSend;
static uint32_t buffersSent;
static uint32_t bufferIdx;  // 0 to BUFFER_NUM-1
static uint32_t lastBufferLength;

sai_transfer_t saiTxPingPongTransfer[2U] = {
    {
        .data     = audioBuff+0,
        .dataSize = (BUFFER_NUM/2)*BUFFER_SIZE,
    },
    {
        .data     = audioBuff+(BUFFER_NUM/2)*BUFFER_SIZE,
        .dataSize = (BUFFER_NUM/2)*BUFFER_SIZE,
    },
};


/*******************************************************************************
 * Code
 ******************************************************************************/

// 16-bit stereo: Two 16-bit words (4 bytes) per sample.
static void PlaybackSine(I2S_Type *base, uint32_t SineWaveFreqHz, uint32_t secondsToPlay)
{
    const uint32_t samplesPerCycle = kSAI_SampleRate48KHz / SineWaveFreqHz;
    const uint32_t bytesPerCycle = (4 * samplesPerCycle); // Stereo, 16-bit samples, so 4 bytes per sample
    const uint32_t cyclesInAudioBuff = (BUFFER_SIZE * BUFFER_NUM) / bytesPerCycle;
    // some space will be unused when (BUFFER_SIZE*BUFFER_NUM) isn't exact multiple of bytesPerCycle
    const uint32_t unfilledBytes = (BUFFER_SIZE * BUFFER_NUM) - bytesPerCycle*cyclesInAudioBuff;
    assert(unfilledBytes==0); // To debug interrupted sinewave output, make sure there are no gaps in buffer

    // From https://en.wikipedia.org/wiki/I%C2%B2S, byte order is as follows:
    // Right channel LSB
    // Right channel MSB
    // Left channel LSB
    // Left channel MSB

    // Generate one cycle of the sine wave
    uint8_t *pAudio = audioBuff; (void)pAudio;
    for (uint32_t i = 0; i &amp;lt; samplesPerCycle; i++)
    {
        uint32_t val = arm_sin_q15( (0x8000 * i) / samplesPerCycle);
        uint8_t LSB = val &amp;amp; 0xFFU;
        uint8_t MSB = (val &amp;gt;&amp;gt; 8U) &amp;amp; 0xFFU;
        *pAudio++ = LSB; *pAudio++ = MSB; // Right channel...
        *pAudio++ = LSB; *pAudio++ = MSB; // Left channel...
    }

    // Copy cycle repeatedly to fit as many cycles as possible into audioBuff
    for (uint32_t i = 1; i &amp;lt; cyclesInAudioBuff; i++)
    {
        memcpy(audioBuff + (i * bytesPerCycle), audioBuff, bytesPerCycle);
    }
    lastBufferLength = BUFFER_SIZE - unfilledBytes;

    /* Send counts according to the playback time needed */
    buffersToSend = kSAI_SampleRate48KHz * secondsToPlay * 4 / BUFFER_SIZE;
    buffersSent   = 0;
    bufferIdx     = 0;

    /* Reset SAI Tx internal logic */
    SAI_TxSoftwareReset(base, kSAI_ResetTypeSoftware);
    /* Do the playback */
    SAI_TransferSendLoopEDMA(base, &amp;amp;txHandle, &amp;amp;saiTxPingPongTransfer[0], 2U);
}

#define SAI_EDMA_callback NULL // suppress callback when using EDMA looping

void audio_init() {
    SAI_Init(SAI1); // enable SAI1 clock
    // Mux (multiplex route) SAI1 TX complete interrupt to DMA channel
    DMAMUX_SetSource(DMAMUX, DMA_channel_8_I2S_SAI1_TX, kDmaRequestMuxSai1Tx);
    DMAMUX_EnableChannel(DMAMUX, DMA_channel_8_I2S_SAI1_TX);
    // Set interrupt priority for EDMA
    const uint32_t SAI_IRQ_priority = (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY /* + 1*/); // Note: +1 is logically 1 lower than configMAX_SYSCALL_INTERRUPT_PRIORITY
    NVIC_SetPriority(DMA8_DMA24_IRQn, SAI_IRQ_priority); // Interrupt priority for EDMA mux'd interrupt
    NVIC_SetPriority(SAI1_IRQn, SAI_IRQ_priority); // Interrupt priority for SAI unit
    // Set up EDMA
    EDMA_CreateHandle(&amp;amp;g_dmaHandle, DMA0, DMA_channel_8_I2S_SAI1_TX);
    SAI_TransferTxCreateHandleEDMA(SAI1, &amp;amp;txHandle, SAI_EDMA_callback, NULL, &amp;amp;g_dmaHandle);
    // I2S mode configuration
    SAI_GetClassicI2SConfig(&amp;amp;saiConfig, kSAI_WordWidth16bits, kSAI_Stereo, 1/* SAI channels used */);
    // the following are actually already set by SAI_GetClassicI2SConfig above...
    saiConfig.syncMode    = kSAI_ModeAsync; // this module is (asynchronously) generating the clock
    saiConfig.masterSlave = kSAI_Master;    // and BT1036A is the slave
    SAI_TransferTxSetConfigEDMA(SAI1, &amp;amp;txHandle, &amp;amp;saiConfig);
    // set bit clock divider
    SAI_TxSetBitClockRate(SAI1, BOARD_BOOTCLOCKRUN_SAI1_MCLK1, kSAI_SampleRate48KHz, kSAI_WordWidth16bits,
                          2/* audio channels (not SAI channels) used, ie 2 for stereo*/);

    #if 1 // ToDo Audio: Remove kludge test here
        vTaskSuspendAll(); // Ensure absolutely no interference by other tasks by suspending everything else
        PlaybackSine(SAI1, /* SineWaveFreqHz= */ 600, /* seconds= */ 120);
        while(1) {};
    #endif
}&lt;/LI-CODE&gt;&lt;P&gt;SAI  configuration"&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAI_config.JPG" style="width: 570px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313858iC30B2E2060CCE47C/image-dimensions/570x570?v=v2" width="570" height="570" role="button" title="SAI_config.JPG" alt="SAI_config.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 00:00:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2006433#M32808</guid>
      <dc:creator>davenadler</dc:creator>
      <dc:date>2024-12-04T00:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2006537#M32810</link>
      <description>&lt;P&gt;PS: Also disabled systick to really prevent interruptions, did not help:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;NVIC_DisableIRQ(SysTick_IRQn); // a bit drastic! Disables FreeRTOS task/timer interrupt.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 03:22:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2006537#M32810</guid>
      <dc:creator>davenadler</dc:creator>
      <dc:date>2024-12-04T03:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2008040#M32834</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/132425"&gt;@davenadler&lt;/a&gt;&amp;nbsp;，&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;I want to to know you call&amp;nbsp;PlaybackSine function one time, and&amp;nbsp;you&amp;nbsp;&lt;SPAN&gt;get interrupted sound&amp;nbsp;?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or you continuously call PlaybackSine&amp;nbsp;function, when and where you call this function?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;mayliu&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 09:33:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2008040#M32834</guid>
      <dc:creator>mayliu1</dc:creator>
      <dc:date>2024-12-05T09:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2008445#M32841</link>
      <description>&lt;P&gt;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/239163"&gt;@mayliu1&lt;/a&gt;- As clearly shown in the code provided above, playback is called exactly once, followed by an infinite loop:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;       PlaybackSine(SAI1, /* SineWaveFreqHz= */ 600, /* seconds= */ 120);
       while(1) {};&lt;/LI-CODE&gt;&lt;P&gt;The 600Hz tone is played forever, with interruptions, as shown in the recording provided above.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 18:26:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2008445#M32841</guid>
      <dc:creator>davenadler</dc:creator>
      <dc:date>2024-12-05T18:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2010610#M32877</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/132425"&gt;@davenadler&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your updated information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I 'm sorry for my later reply.&lt;/P&gt;
&lt;P&gt;I suggest you call&amp;nbsp; PlaybackSine function in SAI_EDMA_callback just like SDK demo did.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;mayliu&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 02:29:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2010610#M32877</guid>
      <dc:creator>mayliu1</dc:creator>
      <dc:date>2024-12-10T02:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAI EDMA looping problem</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2013938#M32921</link>
      <description>&lt;P&gt;I'm sorry &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/239163"&gt;@mayliu1&lt;/a&gt; , but &lt;U&gt;your reply makes absolutely no sense&lt;/U&gt;.&lt;BR /&gt;If you would read the comments and code provided above, you would know that this code&lt;BR /&gt;is based on the SDK example&lt;/P&gt;&lt;PRE&gt;evkmimxrt1024_sai_edma_ping_pong_buffer&lt;/PRE&gt;&lt;P&gt;This uses&lt;/P&gt;&lt;PRE&gt;SAI_TransferSendLoopEDMA(base, &amp;amp;txHandle, &amp;amp;saiTxPingPongTransfer[0], 2U);&lt;/PRE&gt;&lt;P&gt;for which a callback is not appropriate and completely counter-productive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please find someone at NXP who is really familiar with I2S, SAI, and DMA to help with this question?&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2024 19:06:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/SAI-EDMA-looping-problem/m-p/2013938#M32921</guid>
      <dc:creator>davenadler</dc:creator>
      <dc:date>2024-12-15T19:06:28Z</dc:date>
    </item>
  </channel>
</rss>

