AnsweredAssumed Answered

STM3F2 DMA Circular Mode Overwrites Data

Question asked by kern.chris on Mar 22, 2015
Latest reply on Mar 23, 2015 by Clive One

I have a global structure that contains an array of bytes of 1024 elements. I have declared this array towards the beginning of the structure. 

I have set up DMA to import USART3 data into this array. I have set up the DMA in circular mode. The data is placed into the array and loops back around as expected. Unfortunately, it also seems to continue on in the memory address space as I can see (in debug mode) other variables of the structure being overwritten. I am not sure how the DMA writes to two different addresses at the same time, but that's what appears to be happening. Ideas?

void DMA_Config_Rx(uint32_t BaseAddr)
    DMA_InitTypeDef  DMA_InitStructure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); 

    DMA_InitStructure.DMA_Channel = DMA_Channel_4; 
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; // Receive
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BaseAddr;
    DMA_InitStructure.DMA_BufferSize = (uint16_t)1024;
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(USART3->DR);
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
    DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;

    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

    DMA_Init(DMA1_Stream1, &DMA_InitStructure); 

    /* Enable the USART Rx DMA request */

    /* Enable the DMA RX Stream */
    DMA_Cmd(DMA1_Stream1, ENABLE);

I pass the address of the array to this function: DMA_Config_Rx(&My_Struct.RX_Data_Buffer);

As I stated, in debug mode, I can see the RX_Data_Buffer data being written over and over as expected per the circular mode, but I also see other variables in the structure changing. Please advise. Thanks.