SAI1 EDMA problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SAI1 EDMA problem

1,542件の閲覧回数
Sandroom
Contributor III

Hello, I need your help. I am programming imx8ulp m33 core.
I need to output audio data to SAI1, but I have encountered a problem.
If I feed data to SAI1 in an infinite loop (in config_sai_tx() function) then the data comes out but with the wrong sample rate (not 48kHz). If I try to use EDMA (in config_sai_tx_edma() function) then the data does not come out at all, I get FIFO underrun flag.
At the same time, if I use the same code with SAI0 (I use #defile USE_SAI0) the data comes out both through config_sai_tx() function and through config_sai_tx_edma(), but also with the wrong sample rate.
Questions:

1) What is my mistake when initializing SAI1 (#define USE_SAI1), how can I make the data output;

2) why is the sample rate incorrect when the data is output?
I am attaching my code in a file.

タグ(4)
0 件の賞賛
返信
4 返答(返信)

1,518件の閲覧回数
joanxie
NXP TechSupport
NXP TechSupport

did you test based on nxp SDK? if yes, which demo and sdk version did you test? I didn't find config_sai_tx() function and config_sai_tx_edma() function, pls share more detailed information, if you tested based on your own project, pls share with me, for sample rate issue, you need check the root clock for SAI1 is correct or not

0 件の賞賛
返信

1,497件の閲覧回数
Sandroom
Contributor III

Hello, thanks for the reply. I am using nxp sdk 2.16.000, I have rewritten the evk9mimx8ulp_sai_edma_transfer example. I have provided the implementation of the config_sai_tx() and config_sai_tx_edma() functions in the file that I have attached to the first message, and I will also duplicate them at the end of this message.
I have solved the problem with the sample rate for edma by removing the line
config.bitClock.bclkSource = kSAI_BclkSourceBusclk;
in config_sai_tx_edma().
For the option without using edma (config_sai_tx) I think that the problem with the sample rate was caused by calling SAI_TransferSendNonBlocking() too often.
I think the sample rate issue is solved for now, but there is still a problem that when using SAI1 (#define USE_SAI1) I don't get data on the bClk and data pins when using edma (if mclk is turned on i see signal mclk) (function config_sai_tx_edma()) I get a fifo underrun error, it seems that there are some differences in edma initialization for sai1 that I don't know about and therefore edma does not feed data to sai1.

Сode of functions config_sai_tx() and config_sai_tx_edma() :


void config_sai_tx()
{
    sai_transfer_t saiXfer;
    sai_transceiver_t config;

    saiXfer.data = dataForTransfer3;
    saiXfer.dataSize = 480;
    SAI_Init(CURRENT_SAI);

    SAI_TransferTxCreateHandle(CURRENT_SAI, &s_saiTxHandle, saiCallback, NULL);

    SAI_GetClassicI2SConfig(&config, kSAI_WordWidth16bits, kSAI_Stereo, SAI_CHANNEL);

    config.bitClock.bclkSource = kSAI_BclkSourceBusclk;
    config.masterSlave = kSAI_Master;
   
    SAI_TransferTxSetConfig(CURRENT_SAI, &s_saiTxHandle, &config);

    SAI_TxSetBitClockRate(CURRENT_SAI, SAI_CLK, kSAI_SampleRate48KHz, kSAI_WordWidth16bits, 2);

    for(int i=4;i <saiXfer.dataSize; i++){
        dataForTransfer3[i] = 0;
    }

    int sendCount = 0;
    while (true)
    {
       
        if (kStatus_Success == SAI_TransferSendNonBlocking(CURRENT_SAI, &s_saiTxHandle, &saiXfer))
        {
            if (sendCount++ > 1000)
                sendCount = 0;
        }
    }
}


void config_sai_tx_edma()
{

    edma_config_t dmaConfig = {0};

    sai_transceiver_t config;

    EDMA_GetDefaultConfig(&dmaConfig);
    EDMA_Init(DMA0, &dmaConfig);
    EDMA_CreateHandle(&g_dmaHandle, DMA0, DMA_CHAN);

    EDMA_SetChannelMux(DMA0, DMA_CHAN, SAI_DMA_MUX);

    SAI_Init(CURRENT_SAI);

    SAI_TransferTxCreateHandleEDMA(CURRENT_SAI, &txHandle, dmaCallback, NULL, &g_dmaHandle);

    SAI_GetClassicI2SConfig(&config, kSAI_WordWidth16bits, kSAI_Stereo, SAI_CHANNEL);

   // config.bitClock.bclkSource = kSAI_BclkSourceBusclk; by removing this line the sample rate became correct
    config.masterSlave = kSAI_Master;
    config.syncMode = kSAI_ModeAsync; 

    SAI_TransferTxSetConfigEDMA(CURRENT_SAI, &txHandle, &config);


    SAI_TxSetBitClockRate(CURRENT_SAI, SAI_CLK, kSAI_SampleRate48KHz, kSAI_WordWidth16bits, 2);

    sai_transfer_t saiXfer2[2];
    sai_transfer_t saiXfer;


    saiXfer2[0].data = dataForTransfer0;
    saiXfer2[1].data = dataForTransfer1;
    saiXfer2[0].dataSize = 480;
    saiXfer2[1].dataSize = 480;

 
    if (SAI_TransferSendLoopEDMA(CURRENT_SAI, &txHandle, &saiXfer2, 2) != kStatus_Success)
    {
        bool fail;
        fail = true;
    };
}
 
0 件の賞賛
返信

1,468件の閲覧回数
joanxie
NXP TechSupport
NXP TechSupport

you can transfer data via SAI1 without edma successfully, but failed with edma,right? did you only test M core? did you bring up the linux in the same time? and did you test edma sai sampe in the SDK? how about that? I checked the demo in SDK which uses SAI0, did you test the demo in the folder named "edma_transfer" ?

0 件の賞賛
返信

1,456件の閲覧回数
Sandroom
Contributor III
yes, transfer without edma works, the problem is when using edma with sai1, I get destination bus error in edma when trying to send.
I have linux loaded on the board, but in tests I also removed BOARD_HandshakeWithUboot(); (in this case, linux will not start, right?)
I tested the demo in the "edma_transfer" folder and with sai0 it works without problems, but with sai1 I get destination bus error in the MP_ES register. The problem is in my initialization of edma for sai1, or the absence of some important settings specific to sai1 when working with edma?
0 件の賞賛
返信