This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA3XEVM: Please check the DMA SPI mode setting.

Part Number: TDA3XEVM

Hi,

I know that the FIFO SPI mode has only 128byte buffer of tx,rx totally.

so, I am trying to test the DMA SPI mode with master device.

When i test below source, the DMA SPI mode is stopped and does not operate.

I refer to the following sources.(mcspiSample_io.c, mcspiSample_main.c)

The tda3x is slave, and SPI tx, rx data is 154byte each.

Please check the DMA SPI mode setting to operate well.

Regards,

Lee

=================================================================================================

/* Buffer size */
#define BUFLEN          (154)
/* Alignment of buffer for use of L2 cache */
#define BUFALIGN        128
/* Number of Iterations */
#define ITERATION_CNT   100
/* Num Bufs to be issued and reclaimed */
#define NUM_BUFS        3

#define DEBUGS_ON       1

/* MCSPI initial configuration */
void user_mcspi_init(void)
{
    Mcspi_init();

    mcspiPrms.opMode = MCSPI_OPMODE_DMAINTERRUPT;//MCSPI_OPMODE_INTERRUPT;
    mcspiPrms.instNum         = 0;
    mcspiPrms.hwiNumber       = 7;
    mcspiPrms.enableCache     = (UInt32) TRUE;
    mcspiPrms.edma3EventQueue = 0;
    mcspiPrms.enableErrIntr   = (UInt32) FALSE;

    mcspiPrms.spiHWCfgData.masterOrSlave         = MCSPI_COMMMODE_SLAVE;
    mcspiPrms.spiHWCfgData.singleOrMultiChEnable = MCSPI_SINGLE_CHANNEL;
    mcspiPrms.spiHWCfgData.pinOpModes    = MCSPI_PINOPMODE_4PIN;
    mcspiPrms.spiHWCfgData.fifoRxTrigLvl = 154;
    mcspiPrms.spiHWCfgData.fifoTxTrigLvl = 154;
    mcspiPrms.spiHWCfgData.configChfmt[0].charLength = MCSPI_LEN_8BIT;
    mcspiPrms.spiHWCfgData.configChfmt[0].multiWordAccessEnable =
        (UInt32) FALSE;

    mcspiPrms.spiHWCfgData.configChfmt[0].spiChipSelectEnablePol =
            (UInt32) FALSE;

    mcspiPrms.spiHWCfgData.configChfmt[0].clockMode           = MCSPI_MODE0;
    mcspiPrms.spiHWCfgData.configChfmt[0].clockRatioExtension = 0;
    mcspiPrms.spiHWCfgData.configChfmt[0].spiWordInitDelay    = MCSPI_NO_DELAY;
    mcspiPrms.spiHWCfgData.configChfmt[0].trasmitReceiveMode  = MCSPI_BOTH_RXTX;
    mcspiPrms.spiHWCfgData.configChfmt[0].granularityEnable   = (UInt32) TRUE;
    mcspiPrms.spiHWCfgData.configChfmt[0].busFreq             =  2500000;
    mcspiPrms.spiHWCfgData.configChfmt[0].spienHighPolarity   = (UInt32) FALSE;
    mcspiPrms.spiHWCfgData.configChfmt[0].slaveModeChipSelect = MCSPI_SPIEN_0;
    mcspiPrms.spiHWCfgData.configChfmt[0].spiDat0Dir          = MCSPI_OUT;
    mcspiPrms.spiHWCfgData.configChfmt[0].spiDat1Dir          = MCSPI_IN;

    if (MCSPI_OPMODE_POLLED == mcspiPrms.opMode)
    {
        Vps_printf("\r\nMcspi is configured in polled mode\r\n");
    }
    else if (MCSPI_OPMODE_INTERRUPT == mcspiPrms.opMode)
    {
        Vps_printf("\r\nMcspi is configured in interrupt mode\r\n");
    }
    else if (MCSPI_OPMODE_DMAINTERRUPT == mcspiPrms.opMode)
    {
        Vps_printf("\r\nMcspi is configured in dma mode\r\n");
    }
    else
    {
        Vps_printf("\r\nError: unknown mode of operation!!!!!!!!!!\r\n");
    }
}

/* Bind the MCSPI handler with the driver */
void SPI_init(void)
{
    GIO_addDevice("/mcspi0", (xdc_Ptr) &Mcspi_IOMFXNS, &user_mcspi_init, 0, (xdc_Ptr) & mcspiPrms);
}

/* System Init and Board Muxing */
static void spiSampleTask(void)
{
    /* Set the pin Mux */
    Bsp_boardSetPinMux(BSP_DRV_ID_MCSPI, BSP_DEVICE_MCSPI_INST_ID_0,
                       BSP_BOARD_MODE_DEFAULT);

    /* Set the board muxes */
    Bsp_boardSelectDevice(BSP_DRV_ID_MCSPI, BSP_DEVICE_MCSPI_INST_ID_0);
}

/* Initialize the channel attributes */
static void createStream(void)
{
    GIO_Params       ioParams;
    Mcspi_ChanParams chanParams;
    Error_Block      eb;

    Error_init(&eb);

    /*
     * Initialize channel attributes.
     */
    GIO_Params_init(&ioParams);

    /* initialze chanParams */
    Mcspi_ChanParams_init(&chanParams);

    /* update the Edma Handle                                                 */
    chanParams.hEdma = gEdmaHandle;
    chanParams.chipSelTimeControl = MCSPI_CLK_CYCLE0;
    chanParams.fifoEnable         = (UInt32) TRUE;
    chanParams.spiChipSelectHold  = (UInt32) TRUE;
    chanParams.chanNum = 0;

    /* Cross bar evt disabled */
    chanParams.crossBarEvtParam.isCrossBarIntEn  = (UInt32) FALSE;
    chanParams.crossBarEvtParam.intNumToBeMapped = 0xFF;  /* Invalid number */

    ioParams.chanParams = (Ptr) & chanParams;
    ioParams.model      = GIO_Model_ISSUERECLAIM;
    ioParams.numPackets = NUM_BUFS + 1;

    chanParams.useAppSpecifiedDmaEvtNumbers = TRUE;
    chanParams.rxDmaEventNumber = (UInt32) CSL_EDMA3_CHA0_MCSPI0_RX;
    chanParams.txDmaEventNumber = (UInt32) CSL_EDMA3_CHA0_MCSPI0_TX;

    mcspiHandle = GIO_create("/mcspi0", GIO_INOUT, &ioParams, &eb);
    if (mcspiHandle == NULL)
    {
        Vps_printf("\r\nCreate input stream FAILED.\r\n");
        BIOS_exit(0);
    }
    Vps_printf("\r\nCreate input stream completed.\r\n");
}

/* Allocate memory to Rx and Tx buffers */
static void initialize_mcspi0_buf(void)
{
    Error_Block  eb;
    Int32        count = 0;
    IHeap_Handle iheap;

    iheap = HeapMem_Handle_to_xdc_runtime_IHeap(myHeap);
    Error_init(&eb);

    /* Allocate buffers for the GIO buffer exchanges                          */
    for (count = 0; count < (NUM_BUFS); count++)
    {
        rxbuf[count] = (Ptr) Memory_calloc(iheap, BUFLEN, BUFALIGN, &eb);
        if (NULL == rxbuf[count])
        {
            Vps_printf("\r\nMEM_calloc failed.\r\n");
        }
        txbuf[count] = (Ptr) Memory_calloc(iheap, BUFLEN, BUFALIGN, &eb);
        if (NULL == txbuf[count])
        {
            Vps_printf("\r\nMEM_calloc failed.\r\n");
        }
    }
}

/* The prime function issues buffers to the driver. */
static void prime(void)
{

    Int32        count = 0;
    UInt32       tempCount = 0;
    UInt32       size      = 0;
    Int          status    = IOM_COMPLETED;
    UInt8        spiDummyDataCount;
   
    Vps_printf(" In prime\n");
    /* Dummy data to be transmitted from SOC to MCU */
    UInt8 spiDummyData[BUFLEN];

    memset(spiDummyData, 0, BUFLEN);

    for (count = 0; count < (NUM_BUFS); count++)
    {
        spiDummyDataCount = 0;

        for (tempCount = 0; tempCount < BUFLEN; tempCount++)
        {
            ((Uint8 *) txbuf[count])[tempCount] = spiDummyData[spiDummyDataCount++];
        }
    }

    /* Cache writeback after buffer initialization with CPU access */
    BspOsal_cacheWbInvAll();

    /* Call to 'GIO_issue' API to issue buffers to the driver*/
    for (count = 0; count < NUM_BUFS; count++)
    {
        issueDataparam[count].bufLen    = BUFLEN;
        issueDataparam[count].inBuffer  = rxbuf[count];
        issueDataparam[count].outBuffer = txbuf[count];

        size = issueDataparam[count].bufLen;

        /* Issue the first & second empty buffers to the input stream         */
        status = GIO_issue(mcspiHandle, &issueDataparam[count], size, NULL);

        if (status != IOM_PENDING && status != IOM_COMPLETED)
        {
            Vps_printf("\r\nsatus =%d\r\n",status);
            Vps_printf("\r\nFailed to issue empty buffer to stream\r\n");
        }

        #if DEBUGS_ON
        Vps_printf(" Print Data in prime\n");
        Vps_printf("SPI TDA2x-> MCU write frame reply\r\n");
        for(spiDummyDataCount=0;spiDummyDataCount<10/*BUFLEN*/;spiDummyDataCount++ )
        {
            Vps_printf("SPI Data[%d byte]=0x%x\r\n", spiDummyDataCount,issueDataparam[count].outBuffer[spiDummyDataCount]);
        }
        #endif
    }
}

/* Main SPI Function */
Void CreateSpiTask()
{
    UInt32 i=0, tempCount       = 0;
    #if DEBUGS_ON
    UInt32 j=0;
    #endif

    /* Holds the SPI data */
    UInt8 SPIdata[BUFLEN]       = {0};
    volatile Int32   i32Count   = 0;
    Int  status                 = IOM_COMPLETED;
    static int claim_count      = 0;

    /* One time initialization and memory allocation for SPI */
    SPI_init();
    spiSampleTask();
    createStream();
    initialize_mcspi0_buf();
    while(1)
    {
        Vps_printf(" SpiTask...Start \n");

        prime();
        for (i = 0; i < NUM_BUFS; i++)
        {
            #if DEBUGS_ON
            Vps_printf("Claim count is %d\r\n", claim_count);
            #endif
         
         status = GIO_reclaim(mcspiHandle, (Ptr *)&issueDataparam[i], NULL, NULL);

            if (IOM_COMPLETED != status)
            {
                Vps_printf(
                    "Error reclaiming empty buffer from the streams %x"
                    " error = 0x%d\r\n",
                    ((Uint8) (issueDataparam[i].outBuffer[i32Count])),
                    status);
                break;
            }
            claim_count++;
            for (tempCount = 0; tempCount < BUFLEN; )
            {
                if (mcspiPrms.spiHWCfgData.configChfmt[0].charLength <= 8)
                {                  
                    memcpy(SPIdata, issueDataparam[i].inBuffer, BUFLEN * sizeof(UInt8));
                       
                    #if DEBUGS_ON
                    Vps_printf("SPI Read Frame\r\n");

                    for(j=0;j<10/*BUFLEN*/;j++ )
                    {
                        Vps_printf("SPI Data[%d byte]=%x\r\n", j,SPIdata[j]);
                    }
                    #endif
                }
                else
                {
                    Vps_printf("Invalid Frame\r\n");
                }
                tempCount++;
            }
          }

        Vps_printf(" SpiTask...End \n");
    }
}