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.

TMDX570LC43HDK: DMA can't read some data correctly(trying to sci tx)

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

Tool/software:

Hi,

I'm tinkering with TMDX570LC43HDK(TMS570LC4357 mcu). I'm currently trying to send data via SCI using DMA but reading doesn't always work.

Here's my minimal reproducible example code:

/**
srcs	unsigned char *[2]	[0x0000D218 {72 'H'},0x08000294 {72 'H'}]	0x08000284	
[0]	unsigned char *	0x0000D218 "Hello, wor..."	0x08000284	
[1]	unsigned char *	0x08000294 "Hello, wor..."	0x08000288	
 */

void func(void)
{
    // Enable MPU first
    _enable_interrupt_();
    _mpuInit_();
    _mpuEnable_();

    // Initialize peripherals
    sciInit();
    dmaDisable();
    dmaEnable();

    uint8_t *src1 = "Hello, world!\r\n";
    uint8_t src2[] = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\r', '\n'};
    uint32_t count = sizeof(src2) / sizeof(src2[0]);
    uint8_t *srcs[] = {src1, src2};
    
    for (uint8_t i = 0; i < 2; i++)
    {

        g_dmaCTRL g_dmaCTRLPKT = {
            .SADD = (uint32_t)srcs[i],
            .DADD = ((uint32_t)&sciREG1->TD) + 3, // TMS570LC4357 is big endian
            .CHCTRL = 0,
            .FRCNT = count,
            .ELCNT = 1,
            .ELDOFFSET = 0,
            .ELSOFFSET = 0,
            .FRDOFFSET = 0,
            .FRSOFFSET = 0,
            .PORTASGN = PORTA_READ_PORTB_WRITE,
            .RDSIZE = ACCESS_8_BIT,
            .WRSIZE = ACCESS_8_BIT,
            .TTYPE = FRAME_TRANSFER,
            .ADDMODERD = ADDR_INC1,
            .ADDMODEWR = ADDR_FIXED,
            .AUTOINIT = AUTOINIT_OFF,
        };

        dmaReqAssign(DMA_CH0, DMA_REQ29);
        dmaReqAssign(DMA_CH29, DMA_REQ0);
        dmaSetCtrlPacket(DMA_CH0, g_dmaCTRLPKT);
        dmaSetChEnable(DMA_CH0, DMA_HW);
        sciREG1->SETINT = (1 << 8) | (1 << 16);

        while ((dmaREG->BTCFLAG & (1 << DMA_CH0)) == 0)
        {
        }
        dmaREG->BTCFLAG = (1 << DMA_CH0);
        sciREG1->CLEARINT = (1 << 8) | (1 << 16);
    }

    while (1)
    {
    }
}

This code does simple thing: read from src1 and send via sci, then read from src2 and send via sci again then stop.

src1 and src2 contain same data of "Hello, world!" and both are sent using dma, but only src1 transmission succeeds. For src2, remote device receives data filled with 0 instead of original data.

I suspect that the problem is related to their memory location. src1, which points to constant char array, is 0x0000D218 while src2, local uint8_t array, is 0x08000294.

But I'm not sure what exactly is causing the problem and how to solve it. I set no dma memory protection. 

Thank you!