Hi,
I am trying to copy buffer from One to Other In cc2538 using DMA, But It seems more buffers are transferring than the length of buffers. Can any one please look at my code, why its happening, I am first time using DMA.
//***************************************************************************** // // The application must allocate the channel control table. // This one is a full table for all modes and channels. // NOTE: This table must be 1024-byte aligned. // //***************************************************************************** #if defined(__IAR_SYSTEMS_ICC__) #pragma data_alignment=1024 unsigned char ucDMAControlTable[1024]; #else unsigned char ucDMAControlTable[1024] __attribute__ ((aligned(1024))); #endif //***************************************************************************** // // Source and destination buffers used for the DMA transfer. // //***************************************************************************** unsigned char SourceBuffer[16]; unsigned char DestBuffer[16]; //***************************************************************************** // // ISR called when uDMA software transfer is done. // The function will compare the two buffers and report if move was done. // //***************************************************************************** void uDMAIntHandler(void) { uint32_t IntStat = uDMAIntStatus(); printf("IntStat = %d\n", IntStat); uDMAIntClear(IntStat); printf("SRC=%s\n", SourceBuffer); printf("DST=%s\n", DestBuffer); } //***************************************************************************** // // Configure the SysTick and SysTick interrupt with a period of 1 second. // //***************************************************************************** int main(void) { uint16_t i; // // Set the clocking to run directly from the external crystal/oscillator. // (no ext 32k osc, no internal osc) // SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ); // // Set IO clock to the same as system clock // SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ); // // Fill Source buffer with some data // for(i=0; i<16; i++) { SourceBuffer[i] = 'A' + i; } // // Display the initial Src and Dstn buffers on the console. // printf("SRC=%s\n", SourceBuffer); printf("DST=%s\n", DestBuffer); // // Enable the uDMA controller. // uDMAEnable(); // // Set the base for the channel control table. // uDMAControlBaseSet(&ucDMAControlTable[0]); // // No attributes must be set for a software-based transfer. // The attributes are cleared by default, but are explicitly cleared // here, in case they were set elsewhere. // uDMAChannelAttributeDisable(UDMA_CH30_SW, UDMA_ATTR_ALL); // // Now set up the characteristics of the transfer for // 8-bit data size, with source and destination increments // in bytes, and a byte-wise buffer copy. A bus arbitration // size of 8 is used. // uDMAChannelControlSet(UDMA_CH30_SW | UDMA_PRI_SELECT, UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_8 | UDMA_ARB_8); // // The transfer buffers and transfer size are now configured. // The transfer uses AUTO mode, which means that the // transfer automatically runs to completion after the first // request. // uDMAChannelTransferSet(UDMA_CH30_SW | UDMA_PRI_SELECT, UDMA_MODE_AUTO, SourceBuffer, DestBuffer, sizeof(DestBuffer)); // // Enable Interrupt for DMA // IntEnable(INT_UDMA); // // Finally, the channel must be enabled. Because this is a // software-initiated transfer, a request must also be made. // The request starts the transfer. // uDMAChannelEnable(UDMA_CH30_SW); uDMAChannelRequest(UDMA_CH30_SW); // // Put cpu to sleep and wait for interrupt (when DMA transfer is done) // SysCtrlSleep(); // // Loop forever while the SysTick runs. // while(1) { } }
Ouput:
SRC=ABCDEFGHIJKLMNOP
DST=
IntStat = 1073741824
SRC=ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP8901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
DST=ABCDEFGHIJKLMNOP8901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
Expected Output:
SRC=ABCDEFGHIJKLMNOP
DST=
IntStat = 1073741824
SRC=ABCDEFGHIJKLMNOP
DST=ABCDEFGHIJKLMNOP
This code is edit of CC2538 foundation firmware DMA_SW example project.
Thank you