cancel
Showing results for 
Search instead for 
Did you mean: 

DMA overwrites rest of memory [solved]

atsju2
Associate II
Posted on July 06, 2014 at 16:46

Hello,

I am working on STM32L151ZC. I use DMA to continuously read 28 ADC channels

It seems that the DMA is periodicaly (les often than the ''normal operation period'') overwriting memory that it shouldn't access directly.

The DMA schould use 448bytes of memory to store data but sometimes it overwrites about 10000 bytes.

Here is an extract of my initialisation code :

&sharpdefine ADC1_DR_ADDRESS    ((uint32_t)0x40012458)

&sharpdefine NB_MESURES 8

volatile uint16_t ADC_measures[NB_MESURES][28];

DMA_InitTypeDef DMA_InitStruct;

DMA_InitStruct.DMA_PeripheralBaseAddr = ADC1_DR_ADDRESS;

DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t) ADC_measures;

DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;

DMA_InitStruct.DMA_BufferSize = NB_MESURES * 28;

DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;

DMA_InitStruct.DMA_Priority = DMA_Priority_High;

DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel1, &DMA_InitStruct);

#stm32-dma
5 REPLIES 5
Posted on July 06, 2014 at 18:32

Ok, so 448 bytes sounds about right, perhaps the issue isn't with the code you've presented. If it's not too much trouble perhaps you can present a complete/consise example that demonstrates this issue?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
atsju2
Associate II
Posted on July 06, 2014 at 18:46

Thank you clive.

I will try to make a simple example (next week) but I'm quite sure of my code.

Could there be a hardware problem ? Like noise that change the number of chanel to convert.

Posted on July 06, 2014 at 23:13

Could there be a hardware problem ? Like noise that change the number of channel to convert.

Experience suggests that's the least probable cause.

Make sure the Init structure is completely initialized, ie no random values

Use (unit32_t)&ADC1->DR instead of a hard coded address.

Make sure your DMA transfer is memory is not on a stack.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
atsju2
Associate II
Posted on July 07, 2014 at 07:33

Make sure your DMA transfer is memory is not on a stack.

 

Can you tell me how ?

I know what the stack is (and what for) but I don't know realy where it is in memory and ''who'' decides.

The DMA init structure is completely initialized.

When I was trying to make a simple and clean example of the problem the code worked fine. I'm now searching about array copie which would not work like expected (because of me or because of the compiler). I will keep you informed.

atsju2
Associate II
Posted on July 07, 2014 at 21:04

I manualy was copying data into a too small array. So the data where overflowing on the rest of the memory.