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.

AM2634-Q1: SPI DMA Data Transfer Time Calculation

Part Number: AM2634-Q1
Other Parts Discussed in Thread: AM2634

Tool/software:

Hi Teams,

I am working on SPI with AM2634 in DMA Mode with callback, when i am transmitting 11bytes data it's taking 107us when i increase data size100bytes transfer time get increase 888 usec but as per my understanding DMA should not take that much of time to transmit the data. it should be the intimation of DMA to data transfer 

this is my code

/*
* SPI_MATSER_SLAVE.c
*
* Created on: Jun 12, 2024
* Author: Swati
*/

#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"
#include <drivers/hw_include/tistdtypes.h>

#define APP_MCSPI_MSGSIZE (11U)
#define APP_MCSPI_TRANSFER_LOOPCOUNT (11U)

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

volatile bool transferComplete = false;

void spiTxCallback(MCSPI_Handle handle, MCSPI_Transaction *transaction);
void spiRxCallback(MCSPI_Handle handle, MCSPI_Transaction *transaction);

void spiTxCallback(MCSPI_Handle handle, MCSPI_Transaction *transaction)
{
DebugP_log("Transmit callback invoked.\r\n");
transferComplete = true;
}

void spiRxCallback(MCSPI_Handle handle, MCSPI_Transaction *transaction)
{
DebugP_log("Receive callback invoked.\r\n");
transferComplete = true;
}

void *mcspi_transmit_receive_continously(void *args)
{
uint32_t i, j;
MCSPI_Transaction spiTransaction;
uint32_t startTimeInUSecs, elapsedTimeInUsecs;

// Drivers_open();
Board_driversOpen();

DebugP_log("[MCSPI] Transmit and Receive example started ...\r\n");

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

/* Writeback buffer */
CacheP_wb(&gMcspiTxBuffer[0U], sizeof(gMcspiTxBuffer), CacheP_TYPE_ALLD);
CacheP_wb(&gMcspiRxBuffer[0U], sizeof(gMcspiRxBuffer), CacheP_TYPE_ALLD);

/* Print transmitted data */
DebugP_log("Transmitted data on SPI0:\r\n");
for(i = 0U; i < APP_MCSPI_MSGSIZE; i++)
{
DebugP_log("%c ", gMcspiTxBuffer[i]);
}
DebugP_log("\r\n");

/* Initiate transfer on SPI0 (Transmit) */
MCSPI_Transaction_init(&spiTransaction);
spiTransaction.channel = gConfigMcspi0ChCfg[0].chNum; // Ensure correct channel number
spiTransaction.dataSize = 8;
spiTransaction.csDisable = TRUE;
spiTransaction.count = APP_MCSPI_MSGSIZE;
spiTransaction.txBuf = (void *)gMcspiTxBuffer;
spiTransaction.rxBuf = NULL;
spiTransaction.args = NULL;
// spiTransaction.transferCallbackFxn = spiTxCallback;
// spiTransaction.dmaEnable = TRUE; // Enable DMA for this transaction

startTimeInUSecs = ClockP_getTimeUsec();
for(j = 0U; j < APP_MCSPI_TRANSFER_LOOPCOUNT; j++)
{
transferComplete = false;
if (MCSPI_transfer(gMcspiHandle[CONFIG_MCSPI0], &spiTransaction) != SystemP_SUCCESS) {
DebugP_assert(FALSE); /* MCSPI transfer failed!! */
}
while(!transferComplete); // Wait for the transfer to complete
}
elapsedTimeInUsecs = ClockP_getTimeUsec() - startTimeInUSecs;

DebugP_log("----------------------------------------------------------\r\n");
DebugP_log("McSPI Clock %d Hz\r\n", gConfigMcspi0ChCfg[0U].bitRate); // Verify bitRate is set correctly
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,
(Float32)(elapsedTimeInUsecs / (uint32_t)APP_MCSPI_TRANSFER_LOOPCOUNT));
DebugP_log("----------------------------------------------------------\r\n\n");

/* Initiate receive on SPI1 */
MCSPI_Transaction_init(&spiTransaction);
spiTransaction.channel = gConfigMcspi1ChCfg[0].chNum;
spiTransaction.dataSize = 8; // Adjust data size as per your requirements
spiTransaction.csDisable = FALSE;
spiTransaction.count = APP_MCSPI_MSGSIZE;
spiTransaction.txBuf = NULL; // Set txBuf to NULL for receiving
spiTransaction.rxBuf = (void *)gMcspiRxBuffer; // Specify the receive buffer
spiTransaction.args = NULL;
// spiTransaction.transferCallbackFxn = spiRxCallback;
// spiTransaction.dmaEnable = TRUE; // Enable DMA for this transaction

transferComplete = false;
if (MCSPI_transfer(gMcspiHandle[CONFIG_MCSPI1], &spiTransaction) != SystemP_SUCCESS) {
DebugP_log("SPI1 transfer failed\r\n");
} else {
while(!transferComplete); // Wait for the transfer to complete

/* Invalidate cache */
CacheP_inv(&gMcspiRxBuffer[0U], sizeof(gMcspiRxBuffer), CacheP_TYPE_ALLD);

DebugP_log("Received data on SPI1:\r\n");
for(j = 0U; j < APP_MCSPI_MSGSIZE; j++)
{
DebugP_log("%c ", gMcspiRxBuffer[j]);
}
DebugP_log("\r\n");
}

Board_driversClose();
// Drivers_close();

return NULL;
}

and this is my SPI Configuration SPI0 and SPI1 and for SPI using 1MHz frequency


Can you please guide me