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.

AM625-Q1: DMA code behaving differently when compiled in CCS vs with makefile

Part Number: AM625-Q1

Tool/software:

I modified the mcspi_performance_8bit so that it would act as a slave using dma. When compiled and run with CCS (v12.8.1), the code runs fine, but when compiled in a makefile project with SDK (I use version 11.0.0.16, but changing to an older SDK (10.01) did not help), the SPI part seems to work fine, but when inspecting the data in RAM, it has not been updated.

Any idea to what could cause this? Attached my updated syscfg and the c code (and in main you replace mcspi_performance_main(NULL); with mcspi_slave_test(NULL);). 

example.sys.cfg

/*
 * mcspi_slave_test.c
 *
 *  Created on: Oct 23, 2024
 *      Author: 
 */


/*
 *  Copyright (C) 2021-22 Texas Instruments Incorporated
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* This example demonstrates the McSPI RX and TX operation configured
 * in DMA mode of operation.
 *
 * This example sends a known data in the TX mode of length APP_MCSPI_MSGSIZE
 * and then receives the same in RX mode. Internal pad level loopback mode
 * is enabled to receive data.
 * To enable internal pad level loopback mode, D0 pin is configured to both
 * TX Enable as well as RX input pin in the SYSCFG.
 *
 * When transfer is completed, TX and RX buffer data are compared.
 * If data is matched, test result is passed otherwise failed.
 */

#include <kernel/dpl/CacheP.h>
#include <kernel/dpl/DebugP.h>
#include "ti_drivers_config.h"
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"

#define APP_MCSPI_MSGSIZE                   (28U)
//#define APP_MCSPI_MSGSIZE                   (128*2*14U)
#define APP_MCSPI_TRANSFER_LOOPCOUNT        (1U)

uint8_t gMcspiTxBuffer[APP_MCSPI_MSGSIZE] __attribute__((aligned(CacheP_CACHELINE_ALIGNMENT)));
uint8_t gMcspiRxBuffer[APP_MCSPI_MSGSIZE] __attribute__((aligned(CacheP_CACHELINE_ALIGNMENT)));

static SemaphoreP_Object gMcspiISRDoneSem;

void SPI0_callbackFxn(MCSPI_Handle handle,
                     MCSPI_Transaction *transaction)
{
    SemaphoreP_Object *semObj;

    if((NULL != transaction) &&
       (MCSPI_TRANSFER_COMPLETED == transaction->status))
    {
        semObj = (SemaphoreP_Object *) transaction->args;
        if(NULL != semObj)
        {
            SemaphoreP_post(semObj);
        }
    } else {
        DebugP_log("Failed in callback\r\n");
    }
}

void *mcspi_slave_test(void *args)
{
    int32_t             status = SystemP_SUCCESS;
    uint32_t            i, j, t;
    int32_t             transferOK;
    MCSPI_Transaction   spiTransaction;
    uint64_t            startTimeInUSec, elapsedTimeInUsecs;

    DebugP_log("[MCSPI] SPI slave test started (%d bytes per packet)...\r\n", APP_MCSPI_MSGSIZE);

    status = SemaphoreP_constructBinary(&gMcspiISRDoneSem, 0);
    DebugP_assert(SystemP_SUCCESS == status);

    /* Memfill buffers */
    for(i = 0U; i < APP_MCSPI_MSGSIZE; i++)
    {
        //gMcspiTxBuffer[i] = i + 1U;
        gMcspiTxBuffer[i] = 0U;
        gMcspiRxBuffer[i] = 0U;
    }

    //GPIO_setDirMode(gpioBaseAddr, pinNum, GPIO_LED_DIR);
    GPIO_pinWriteHigh(AFE_RESET_BASE_ADDR, AFE_RESET_PIN);
    ClockP_sleep(2);

    t = 0;
    while (1) {
        /* Writeback buffer */
        CacheP_wb(&gMcspiTxBuffer[0U], sizeof(gMcspiTxBuffer), CacheP_TYPE_ALLD);
        CacheP_wb(&gMcspiRxBuffer[0U], sizeof(gMcspiRxBuffer), CacheP_TYPE_ALLD);

        /* Initiate transfer */
        MCSPI_Transaction_init(&spiTransaction);
        spiTransaction.channel  = gConfigMcspi0ChCfg[0].chNum;
        spiTransaction.dataSize = 8U;
        spiTransaction.csDisable = TRUE;
        spiTransaction.count    = APP_MCSPI_MSGSIZE / (spiTransaction.dataSize/8);
        spiTransaction.txBuf    = (void *)gMcspiTxBuffer;
        spiTransaction.rxBuf    = (void *)gMcspiRxBuffer;
        spiTransaction.args     = &gMcspiISRDoneSem;    /* Pass semaphore */
        startTimeInUSec = ClockP_getTimeUsec();
        transferOK = 0;
        t++;
        startTimeInUSec = ClockP_getTimeUsec();
        GPIO_pinWriteHigh(AFE_RESET_BASE_ADDR, AFE_SPARE_GPIO_PIN);
        for(j = 0U; j < APP_MCSPI_TRANSFER_LOOPCOUNT; j++)
        {
            transferOK = MCSPI_transfer(gMcspiHandle[CONFIG_MCSPI0], &spiTransaction);
        }
        elapsedTimeInUsecs = ClockP_getTimeUsec() - startTimeInUSec;

        if (SystemP_SUCCESS != transferOK)
        {
            DebugP_log("TransferOk %d\r\n", transferOK);
            DebugP_assert(FALSE); /* MCSPI transfer failed!! */
        }
        //DebugP_log("A ok\r\n");
        DebugP_log(".");
        status = SemaphoreP_pend(&gMcspiISRDoneSem, SystemP_WAIT_FOREVER);
        DebugP_assert(status == SystemP_SUCCESS);
        GPIO_pinWriteLow(AFE_RESET_BASE_ADDR, AFE_SPARE_GPIO_PIN);

        DebugP_log("----------------------------------------------------------\r\n");
        //DebugP_log("Transfer %d McSPI Clock %d Hz\r\n", t, gConfigMcspi0ChCfg[0U].bitRate);
        //DebugP_log("----------------------------------------------------------\r\n");
        //DebugP_log("Data Width \tData Length \tTransfer Time (micro sec)\r\n");
        //DebugP_log("%u\t\t%u\t\t%5.2f\r\n", spiTransaction.dataSize, APP_MCSPI_MSGSIZE,
        //                    (float)elapsedTimeInUsecs / APP_MCSPI_TRANSFER_LOOPCOUNT);
        //DebugP_log("----------------------------------------------------------\r\n\n");


        /* Invalidate cache */
        CacheP_inv(&gMcspiRxBuffer[0U], sizeof(gMcspiRxBuffer), CacheP_TYPE_ALLD);
        /* Compare data */
        uint8_t first = gMcspiRxBuffer[0];
        for(i = 0U; i < APP_MCSPI_MSGSIZE; i++)
        {
            if (i < 10) {
                DebugP_log("%d: %d\r\n", i, gMcspiRxBuffer[i]);
            }
            if (gMcspiRxBuffer[i] != i) { //(i+1)*first % 256) {
                DebugP_log("Data Mismatch at offset %d, expected %d got %d\r\n", i, (i+1)*first % 256, gMcspiRxBuffer[i]);
                status = SystemP_FAILURE;   /* Data mismatch */
                break;
            }

            gMcspiRxBuffer[i] = 5;
        }
        ClockP_sleep(1);

    }
    //DebugP_log("All data:\r\n");
    //for(i = 0U; i < APP_MCSPI_MSGSIZE*2; i++)
    //{
    //    DebugP_log("%d: %d\r\n", i, gMcspiRxBuffer[i]);
    //}
    if(SystemP_SUCCESS == status)
    {
        DebugP_log("All tests have passed!!\r\n");
    }
    else
    {
        DebugP_log("Some tests have failed!!\r\n");
    }

    return NULL;
}


PS. I had to rename example.syscfg to example.sys.cfg as the file wouldn't upload otherwise..