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.

RM48L952: MibSpi Tx and Rx using DMA

Part Number: RM48L952
Other Parts Discussed in Thread: HALCOGEN, TMS570LC4357

Hello,

I am working on RM48L952 HDK. I am using MibSPI1 as master which will send the data and MibSPI5 as a slave which will receive the data. I have tried the mibspi with Dma example given in Halcogen and modified it based on my requirement. I will provide the code below:

* example data Pattern configuration */
#define D_SIZE 127

void loadDataPattern(uint32 psize, uint16* pptr);
//void mibspiEnableInternalLoopback(mibspiBASE_t *mibspi);
void dmaConfigCtrlTxPacket(uint32 sadd,uint32 dadd,uint32 dsize);
void dmaConfigCtrlRxPacket(uint32 sadd,uint32 dadd,uint32 dsize);
void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel, uint32 rxchannel);

uint16 TX_DATA[D_SIZE]; /* transmit buffer in sys ram */
uint16 RX_DATA[D_SIZE]= {0}; /* receive buffer in sys ram */

g_dmaCTRL g_dmaCTRLPKT_Tx; /* dma control packet configuration stack */
g_dmaCTRL g_dmaCTRLPKT_Rx;
/* USER CODE END */


/* USER CODE BEGIN (2) */
/* USER CODE END */


void main(void)
{
/* USER CODE BEGIN (3) */

/* - creating a data chunk in system ram to start with ... */
loadDataPattern(D_SIZE,&TX_DATA[0]);

/* - initializing mibspi - enabling tg 0 , length 127 (halcogen file)*/
mibspiInit();

/* - assigning dma request: channel-0 with request line - 1 */
dmaReqAssign(0,1 );
dmaReqAssign(1,6 );

/* - configuring dma control packets */
dmaConfigCtrlTxPacket((uint32)(&TX_DATA),(uint32)(&(mibspiRAM1->tx[0].data)),D_SIZE);
dmaConfigCtrlRxPacket((uint32)(&(mibspiRAM3->rx[0].data)),(uint32)(&RX_DATA),D_SIZE);
/* upto 32 control packets are supported. */

/* - setting dma control packets */
dmaSetCtrlPacket(DMA_CH0,g_dmaCTRLPKT_Tx);
dmaSetCtrlPacket(DMA_CH1,g_dmaCTRLPKT_Rx);

/* - setting the dma channel to trigger on h/w request */
dmaSetChEnable(DMA_CH0, DMA_HW);
dmaSetChEnable(DMA_CH1, DMA_HW);

/* - configuring the mibspi dma , channel 0 , tx line -0 , rxline -1 */
/* - refer to the device data sheet dma request source for mibspi tx/rx */
mibspiDmaConfig(mibspiREG1,0,0,1);

/* - enabling dma module */
dmaEnable();

/* - start the mibspi transfer tg 0 */
mibspiTransfer(mibspiREG1,0 );

/* ... wait until transfer complete */
while(!(mibspiIsTransferComplete(mibspiREG1,0)))
{
};

/* copy from mibspi ram to sys ram */
mibspiGetData(mibspiREG5, 0, RX_DATA);

while(1); /* loop forever */

/* USER CODE END */
}

/* USER CODE BEGIN (4) */
void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel, uint32 rxchannel)
{
uint32 bufid = 0;
uint32 icount = 0;

/* setting transmit and receive channels */
mibspi->DMACTRL[channel] |= (((rxchannel<<4)|txchannel) << 16);

/* enabling transmit and receive dma */
mibspi->DMACTRL[channel] |= 0x8000C000;

/* setting Initial Count of DMA transfers and the buffer utilized for DMA transfer */
mibspi->DMACTRL[channel] |= (icount << 8) |(bufid<<24);

}

void dmaConfigCtrlTxPacket(uint32 sadd,uint32 dadd,uint32 dsize)
{
g_dmaCTRLPKT_Tx.SADD = sadd; /* source address */
g_dmaCTRLPKT_Tx.DADD = dadd; /* destination address */
g_dmaCTRLPKT_Tx.CHCTRL = 0; /* channel control */
g_dmaCTRLPKT_Tx.FRCNT = 1; /* frame count */
g_dmaCTRLPKT_Tx.ELCNT = dsize; /* element count */
g_dmaCTRLPKT_Tx.ELDOFFSET = 4; /* element destination offset */
g_dmaCTRLPKT_Tx.ELSOFFSET = 0; /* element destination offset */
g_dmaCTRLPKT_Tx.FRDOFFSET = 0; /* frame destination offset */
g_dmaCTRLPKT_Tx.FRSOFFSET = 0; /* frame destination offset */
g_dmaCTRLPKT_Tx.PORTASGN = 4; /* port b */
g_dmaCTRLPKT_Tx.RDSIZE = ACCESS_16_BIT; /* read size */
g_dmaCTRLPKT_Tx.WRSIZE = ACCESS_16_BIT; /* write size */
g_dmaCTRLPKT_Tx.TTYPE = FRAME_TRANSFER ; /* transfer type */
g_dmaCTRLPKT_Tx.ADDMODERD = ADDR_INC1; /* address mode read */
g_dmaCTRLPKT_Tx.ADDMODEWR = ADDR_OFFSET; /* address mode write */
g_dmaCTRLPKT_Tx.AUTOINIT = AUTOINIT_ON; /* autoinit */
}

void dmaConfigCtrlRxPacket(uint32 sadd,uint32 dadd,uint32 dsize)
{
g_dmaCTRLPKT_Rx.SADD = sadd; /* source address */
g_dmaCTRLPKT_Rx.DADD = dadd; /* destination address */
g_dmaCTRLPKT_Rx.CHCTRL = 0; /* channel control */
g_dmaCTRLPKT_Rx.FRCNT = 1; /* frame count */
g_dmaCTRLPKT_Rx.ELCNT = dsize; /* element count */
g_dmaCTRLPKT_Rx.ELDOFFSET = 4; /* element destination offset */
g_dmaCTRLPKT_Rx.ELSOFFSET = 0; /* element destination offset */
g_dmaCTRLPKT_Rx.FRDOFFSET = 0; /* frame destination offset */
g_dmaCTRLPKT_Rx.FRSOFFSET = 0; /* frame destination offset */
g_dmaCTRLPKT_Rx.PORTASGN = 4; /* port b */
g_dmaCTRLPKT_Rx.RDSIZE = ACCESS_16_BIT; /* read size */
g_dmaCTRLPKT_Rx.WRSIZE = ACCESS_16_BIT; /* write size */
g_dmaCTRLPKT_Rx.TTYPE = FRAME_TRANSFER ; /* transfer type */
g_dmaCTRLPKT_Rx.ADDMODERD = ADDR_INC1; /* address mode read */
g_dmaCTRLPKT_Rx.ADDMODEWR = ADDR_OFFSET; /* address mode write */
g_dmaCTRLPKT_Rx.AUTOINIT = AUTOINIT_ON; /* autoinit */
}

void loadDataPattern(uint32 psize, uint16* pptr)
{
int i;
for(i=0;i<psize;i++)
{
pptr[i] = i;
}
}
/* USER CODE END */

I am unable to receive the data at the mibspi5 end. What is wrong with the code? I am not sure the channel and request line am using for mibspi5 is correct or not. I have connected the mibspi1 and mibsi5 (SOMI to SOMI, SIMO to SIMO, CLK to CLK and CS_1 to CS_1). In Halcogen I have used CS_1 for tg0 for both.

Thanks

 

  • Thanks Wang,

    I am able to transmit and receive data using DMA. I used other thread e2e.ti.com/.../mibspi-as-slave-with-dma

    Now I want to send a large chunk of data i.e. 610 byes. Is it possible to send this large data? Also, I wanted to know how much data I can send in one shot.

    Thanks,

  • Hello Wang,

    I am able to send 256 bytes of data. In Halcogen I have set the tg0 and tg1 length as 128 for MibSPI1 which is my master and I can see 256 bytes of data, but if am using tg2 and tg3 by setting the length to 128 still only 256 bytes I can see.

    Can you help me to set up this till 610 bytes.

    /* USER CODE BEGIN (0) */
    /* USER CODE END */

    /* Include Files */

    #include "sys_common.h"

    /* USER CODE BEGIN (1) */
    #include "mibspi.h"
    #include "sys_dma.h"
    #include "stdio.h"
    /* USER CODE END */

    /** @fn void main(void)
    * @brief Application main function
    * @note This function is empty by default.
    *
    * This function is called after startup.
    * The user can use this function to implement the application.
    */

    /* USER CODE BEGIN (2) */
    void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel, uint32 rxchannel);
    void dmaConfigCtrlRxPacket(uint32 sadd,uint32 dadd,uint32 dsize);
    void dmaConfigCtrlTxPacket(uint32 sadd,uint32 dadd,uint32 dsize);
    void loadDataPattern1(uint32 psize, uint8* pptr);
    void loadDataPattern3(uint32 psize, uint8* pptr);
    #define D_SIZE 610
    #define DMA_CH_TX DMA_CH0
    #define DMA_CH_RX DMA_CH1

    /* SPI1 transmit buffer in sys ram */
    uint8 mibSPI1_TX_Data[D_SIZE]= "$GPZDA,hhmmss.ss,dd,mm,yyyy,aa,bb*CS<CR><LF>$GPGLL,llll.lllll,a,yyyyy.yyyyy,b,hhmmss.ss,c,a*CS<CR><LF>$GPGSV,t,n,xx,aa,ee,zzz,cc,aa,ee,zzz,cc,aa,ee,zzz,cc,aa,ee,zzz,cc*CS<CR><LF>$GPRMC,hhmmss.ss,A,llll.lllll,A,yyyyy.yyyyy,B,ssss.ss,hhh.hh,ddmmyy,mm.m,D,B*CS<CR><LF>$GPGGA,hhmmss.ss,llll.lllll,A,yyyyy.yyyyy,B,q,nn,hh.h,aaaaa.a,M,sss.s,M,a.a,aaaa*CS<CR><LF>$GPGSA,a,m,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,pp.p,hh.h,vv.v*CS<CR><LF>$GPVTG,ddd.dd,T,ddd.dd,M,ssss.ss,N,ssss.ss,K,a*CS<CR><LF>";
    /* SPI2 transmit buffer in sys ram */
    uint8 mibSPI3_TX_Data[D_SIZE];
    /* SPI1 receive buffer in sys ram */
    uint8 mibSPI1_RX_Data[D_SIZE]= {0};
    /* SPI2 receive buffer in sys ram */
    uint8 mibSPI3_RX_Data[D_SIZE]= {0};

    g_dmaCTRL g_dmaCTRLPKT_RX; /* dma control packet configuration stack for receive */
    g_dmaCTRL g_dmaCTRLPKT_TX; /* dma control packet configuration stack for transmit */
    /* USER CODE END */

    int main(void)
    {
    /* USER CODE BEGIN (3) */
    uint32 i;
    /* - initializing mibspi - enabling Transfer Group 0 , length 128 (halcogen file)*/
    mibspiInit();
    //loadDataPattern1(D_SIZE,&mibSPI1_TX_Data[0]);
    loadDataPattern3(D_SIZE,&mibSPI3_TX_Data[0]);
    /****************************************/

    /* DMA Request Sources: MIBSPI3[0] -> request line 15 */
    dmaReqAssign(DMA_CH_TX,15 ); /* Transmit data DMA channel enable. */
    /* DMA Request Sources: MIBSPI3[1] -> request line 14 */
    dmaReqAssign(DMA_CH_RX,14 ); /* Receive data DMA channel enable. */
    /* - configuring dma control packet for sending data to mibSPI3 tx buffer*/
    dmaConfigCtrlRxPacket((uint32)&(mibspiRAM3->rx[0].data),(uint32)&(mibSPI3_RX_Data),D_SIZE);
    /* - configuring dma control packet for receiving data from mibSPI3 rx buffer*/
    dmaConfigCtrlTxPacket((uint32)&(mibSPI3_TX_Data),(uint32)&(mibspiRAM3->tx[0].data),D_SIZE);

    /* - setting dma control packets for transmit */
    dmaSetCtrlPacket(DMA_CH_TX,g_dmaCTRLPKT_TX);
    /* - setting dma control packets for Receive */
    dmaSetCtrlPacket(DMA_CH_RX,g_dmaCTRLPKT_RX);

    /* - configuring the mibspi dma , channel 0 , txline -15 , rxline -14 */
    mibspiDmaConfig(mibspiREG3,DMA_CH_TX,14,15);
    /****************************************/

    /* DMA Request Sources: MIBSPI1[0] -> request line 1 */
    dmaReqAssign(DMA_CH_TX,1 );
    /* - assigning dma request: channel-1 */
    /* DMA Request Sources: MIBSPI1[1] -> request line 0 */
    dmaReqAssign(DMA_CH_RX,0 );

    /* - configuring dma control packet for sending data to mibSPI1 tx buffer*/
    dmaConfigCtrlTxPacket((uint32)&(mibSPI1_TX_Data),(uint32)&(mibspiRAM1->tx[0].data),D_SIZE);
    /* - configuring dma control packet for receiving data from mibSPI1 rx buffer*/
    dmaConfigCtrlRxPacket((uint32)&(mibspiRAM1->rx[0].data),(uint32)&(mibSPI1_RX_Data),D_SIZE);

    /* - setting dma control packets for transmit */
    dmaSetCtrlPacket(DMA_CH_TX,g_dmaCTRLPKT_TX); // RAM to MIBSPIRAM
    /* - setting dma control packets for Receive */
    dmaSetCtrlPacket(DMA_CH_RX,g_dmaCTRLPKT_RX); // MIBSPIRAM to RAM

    /* - configuring the mibspi dma , channel 0 , txline -1 , rxline -0 */
    mibspiDmaConfig(mibspiREG1,DMA_CH_TX,0,1);
    /****************************************/
    /* - setting the dma channel to trigger on h/w request */
    dmaSetChEnable(DMA_CH_TX,DMA_HW);
    dmaSetChEnable(DMA_CH_RX, DMA_HW);

    /* Enable Interrupt after reception of data */
    dmaEnableInterrupt(DMA_CH_TX,FTC); /* FTC: Frame Transfer Complete Interrupt */
    dmaEnableInterrupt(DMA_CH_RX,FTC); /* FTC: Frame Transfer Complete Interrupt */

    _enable_IRQ();
    /* enable DMA now to make sure it's ready to take requests */
    dmaEnable();

    /**** Set up slave *****/

    /* Initiate the receive buffer */
    mibspiSetData(mibspiREG3,1,mibSPI3_TX_Data);
    /* - start the mibspi transfer tg 1 */
    mibspiTransfer(mibspiREG3,1);

    /**** Set up master ****/

    /* Initiate the transmit buffer */
    mibspiSetData(mibspiREG1,0,mibSPI1_TX_Data);
    /* - start the mibspi transfer tg 0 */
    mibspiTransfer(mibspiREG1,0);

    /* ... wait until transfer complete */
    while(!(mibspiIsTransferComplete(mibspiREG1,0)));
    while(!(mibspiIsTransferComplete(mibspiREG3,1)));

    /* copy from mibspi ram to sys ram */
    mibspiGetData(mibspiREG3, 1, mibSPI3_RX_Data);

    for(i=0;i<=D_SIZE;i++)
    {
    printf("\r\n%d mibSPI1_TX_Data: 0x%04x mibSPI3_RX_Data: 0x%04x ",i, mibSPI1_TX_Data[i], mibSPI3_RX_Data[i]);
    }
    while(1);
    /* USER CODE END */

    return 0;
    }


    /* USER CODE BEGIN (4) */
    void dmaConfigCtrlTxPacket(uint32 sadd,uint32 dadd,uint32 dsize)
    {
    g_dmaCTRLPKT_TX.SADD = sadd; /* source address */
    g_dmaCTRLPKT_TX.DADD = dadd; /* destination address */
    g_dmaCTRLPKT_TX.CHCTRL = 0; /* channel control */
    g_dmaCTRLPKT_TX.FRCNT = 1; /* frame count */
    g_dmaCTRLPKT_TX.ELCNT = dsize; /* element count */
    g_dmaCTRLPKT_TX.ELDOFFSET = 4; /* element destination offset */
    g_dmaCTRLPKT_TX.ELSOFFSET = 0; /* element source offset */
    g_dmaCTRLPKT_TX.FRDOFFSET = 0; /* frame destination offset */
    g_dmaCTRLPKT_TX.FRSOFFSET = 0; /* frame destination offset */
    g_dmaCTRLPKT_TX.PORTASGN = 4; /* port b */
    g_dmaCTRLPKT_TX.RDSIZE = ACCESS_16_BIT; /* read size */
    g_dmaCTRLPKT_TX.WRSIZE = ACCESS_16_BIT; /* write size */
    g_dmaCTRLPKT_TX.TTYPE = FRAME_TRANSFER ; /* transfer type */
    g_dmaCTRLPKT_TX.ADDMODERD = ADDR_INC1; /* address mode read */
    g_dmaCTRLPKT_TX.ADDMODEWR = ADDR_OFFSET; /* address mode write */
    g_dmaCTRLPKT_TX.AUTOINIT = AUTOINIT_ON; /* autoinit */
    }

    void dmaConfigCtrlRxPacket(uint32 sadd,uint32 dadd,uint32 dsize)
    {
    g_dmaCTRLPKT_RX.SADD = sadd; /* source address */
    g_dmaCTRLPKT_RX.DADD = dadd; /* destination address */
    g_dmaCTRLPKT_RX.CHCTRL = 0; /* channel control */
    g_dmaCTRLPKT_RX.FRCNT = 1; /* frame count */
    g_dmaCTRLPKT_RX.ELCNT = dsize; /* element count */
    g_dmaCTRLPKT_RX.ELDOFFSET = 0; /* element destination offset */
    g_dmaCTRLPKT_RX.ELSOFFSET = 4; /* element source offset */
    g_dmaCTRLPKT_RX.FRDOFFSET = 0; /* frame destination offset */
    g_dmaCTRLPKT_RX.FRSOFFSET = 0; /* frame destination offset */
    g_dmaCTRLPKT_RX.PORTASGN = 4; /* port b */
    g_dmaCTRLPKT_RX.RDSIZE = ACCESS_16_BIT; /* read size */
    g_dmaCTRLPKT_RX.WRSIZE = ACCESS_16_BIT; /* write size */
    g_dmaCTRLPKT_RX.TTYPE = FRAME_TRANSFER ; /* transfer type */
    g_dmaCTRLPKT_RX.ADDMODERD = ADDR_OFFSET; /* address mode read */
    g_dmaCTRLPKT_RX.ADDMODEWR = ADDR_INC1; /* address mode write */
    g_dmaCTRLPKT_RX.AUTOINIT = AUTOINIT_ON; /* autoinit */
    }

    void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel, uint32 rxchannel)
    {
    uint32 bufid = D_SIZE - 1;
    uint32 icount = 0;

    /* setting transmit and receive channels */
    mibspi->DMACTRL[channel] |= (((rxchannel<<4)|txchannel) << 16);

    /* enabling transmit dma */
    mibspi->DMACTRL[channel] |= 0x00008000; // RX DMA Enable
    mibspi->DMACTRL[channel] |= 0x00004000; // TX DMA Enable

    /* setting Initial Count of DMA transfers and the buffer utilized for DMA transfer */
    mibspi->DMACTRL[channel] |= (icount << 8) |(bufid<<24);

    }

    void loadDataPattern1(uint32 psize, uint8* pptr)
    {
    int i;
    for(i=0;i<psize;i++)
    {
    pptr[i] = i;
    }
    }

    void loadDataPattern3(uint32 psize, uint8* pptr)
    {
    int i;
    for(i=0;i<psize;i++)
    {
    pptr[i] = i+128;
    }
    }
    /* USER CODE END */

    Thanks

  • Using the DMAxCOUNT and DMACTNTLEN register, MibSPI can transfer a block of up to 65535 (65K) words.

  • Hello Wang,

    I have tried using DMAxCOUNT and DMACTNTLEN but still am able to transfer only 256 bytes of data. Can you please check if what I have done is correct or not?

    3364.SPI.zip

  • Any update on this?

  • I replied two days ago, but I don't know why my answer was not posted.

    In your code, MibSPI1 and MibSPI3 use the same DMA channels, please use separate DMA channels for MibSPI3. The element size in your DMA package configuration is 610. I suggest you use TG size as the element size. 

    If you use 10 buffers of TMibSPI1 G0 for transfer, and 10 buffers of MibSPI3 TG0 to receive data, and total data size is 610 halfwords,  you can configurate the element size = 10 and frame size = 610/10=61

  • Please change your MibSPI DMA configuration as I did in the below function:

    void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel, uint32 rxchannel)
    {
    uint32 bufid;

    if (mibspi == mibspiREG1){
    bufid = tgPSTART1[channel] + E_COUNT - 1;
    }else{
    bufid = tgPSTART3[channel] + E_COUNT - 1;
    }


    /* setting transmit and receive channels */
    mibspi->DMACTRL[channel] |= (rxchannel << 20) | (txchannel << 16);

    if (F_COUNT > 1) {
    mibspi->TGCTRL[channel] &= 0xBFFFFFFF; // Disable ONESHOT
    } else {
    mibspi->TGCTRL[channel] |= 0x40000000; // Enable ONESHOT
    }

    /* enabling transmit and receive dma */
    mibspi->DMACTRL[channel] |= 0x8000C000;

    /* setting Initial Count of DMA transfers and the buffer utilized for DMA transfer */
    mibspi->DMACTRL[channel] |= (bufid<<24);

    /* Enable Large count transfer */
    mibspi->DMACNTLEN = 0x1;
    mibspi->DMACOUNT[channel] = (F_COUNT - 1) << 16;

    }

  • Hello Wang,

    Sorry for replying late. I was busy in some other work and could not see this.

    As you suggested I changed the element size to 128 as the buffer size of tg 0 is 128. Also I changed the frame count to 610/128 = 5(round off).

    And I changed the MibSPI DMA configuration as given by you. I just wanted to know what is tgPSTART1 E_COUNT and F_COUNT in your code.

  • tgPSTART1: TG start address. It is 0 for TG0.

    E_COUNT: Element count: 128

    F_COUNT: number of Frame, 5

  • Hello Wang,

    I changed the code but now even the first 255 bytes are also corrupted. The changed piece of code is below:

    void dmaConfigCtrlTxPacket(uint32 sadd,uint32 dadd,uint32 dsize)

    {

    g_dmaCTRLPKT_TX.SADD = sadd; /* source address */

    g_dmaCTRLPKT_TX.DADD = dadd; /* destination address */

    g_dmaCTRLPKT_TX.CHCTRL = 0; /* channel control */

    g_dmaCTRLPKT_TX.FRCNT = 5; /* frame count */

    g_dmaCTRLPKT_TX.ELCNT = 128; /* element count */

    g_dmaCTRLPKT_TX.ELDOFFSET = 4; /* element destination offset */

    g_dmaCTRLPKT_TX.ELSOFFSET = 0; /* element source offset */

    g_dmaCTRLPKT_TX.FRDOFFSET = 0; /* frame destination offset */

    g_dmaCTRLPKT_TX.FRSOFFSET = 0; /* frame destination offset */

    g_dmaCTRLPKT_TX.PORTASGN = 4; /* port b */

    g_dmaCTRLPKT_TX.RDSIZE = ACCESS_16_BIT; /* read size */

    g_dmaCTRLPKT_TX.WRSIZE = ACCESS_16_BIT; /* write size */

    g_dmaCTRLPKT_TX.TTYPE = BLOCK_TRANSFER ; /* transfer type */

    g_dmaCTRLPKT_TX.ADDMODERD = ADDR_INC1; /* address mode read */

    g_dmaCTRLPKT_TX.ADDMODEWR = ADDR_OFFSET; /* address mode write */

    g_dmaCTRLPKT_TX.AUTOINIT = AUTOINIT_ON; /* autoinit */

    }

    void dmaConfigCtrlRxPacket(uint32 sadd,uint32 dadd,uint32 dsize)

    {

    g_dmaCTRLPKT_RX.SADD = sadd; /* source address */

    g_dmaCTRLPKT_RX.DADD = dadd; /* destination address */

    g_dmaCTRLPKT_RX.CHCTRL = 0; /* channel control */

    g_dmaCTRLPKT_RX.FRCNT = 5; /* frame count */

    g_dmaCTRLPKT_RX.ELCNT = 128; /* element count */

    g_dmaCTRLPKT_RX.ELDOFFSET = 0; /* element destination offset */

    g_dmaCTRLPKT_RX.ELSOFFSET = 4; /* element source offset */

    g_dmaCTRLPKT_RX.FRDOFFSET = 0; /* frame destination offset */

    g_dmaCTRLPKT_RX.FRSOFFSET = 0; /* frame destination offset */

    g_dmaCTRLPKT_RX.PORTASGN = 4; /* port b */

    g_dmaCTRLPKT_RX.RDSIZE = ACCESS_16_BIT; /* read size */

    g_dmaCTRLPKT_RX.WRSIZE = ACCESS_16_BIT; /* write size */

    g_dmaCTRLPKT_RX.TTYPE = BLOCK_TRANSFER ; /* transfer type */

    g_dmaCTRLPKT_RX.ADDMODERD = ADDR_OFFSET; /* address mode read */

    g_dmaCTRLPKT_RX.ADDMODEWR = ADDR_INC1; /* address mode write */

    g_dmaCTRLPKT_RX.AUTOINIT = AUTOINIT_ON; /* autoinit */

    }

    void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel, uint32 rxchannel)

    {

    uint32 bufid;

    if (mibspi == mibspiREG1){

    bufid = 0 + 128 - 1;

    }else{

    bufid = 3 + 128 - 1;

    }

     

    /* setting transmit and receive channels */

    mibspi->DMACTRL[channel] |= (rxchannel << 20) | (txchannel << 16);

    if (5 > 1) {

    mibspi->TGCTRL[channel] &= 0xBFFFFFFF; // Disable ONESHOT

    } else {

    mibspi->TGCTRL[channel] |= 0x40000000; // Enable ONESHOT

    }

    /* enabling transmit and receive dma */

    mibspi->DMACTRL[channel] |= 0x8000C000;

    /* setting Initial Count of DMA transfers and the buffer utilized for DMA transfer */

    mibspi->DMACTRL[channel] |= (bufid<<24);

    /* Enable Large count transfer */

    mibspi->DMACNTLEN = 0x1;

    mibspi->DMACOUNT[channel] = (5 - 1) << 16;

    }

     

  • This is my example project. The number of buffers in my setup is 64.

    MibSPI1 is SPI master, MibSPI3 is SPI slave. The code was tested on TMS570LS12x Launchpad.

     

    TMS570LS1224_MibSPI_DMA_BigBlock.zip

  • Thanks for this Wang,

    I will check this and try to find out where I was going wrong.

    Thanks once again.

  • You can change the number of buffer in TG0. After than, you need to change the E_COUNT in sys_main.c