cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4xx and TIM2->ADC->DMA + SDIO->DMA problems

ulf
Associate
Posted on January 28, 2013 at 14:14

I am building a data logger that will sample 12 ADC channels and store the results on an SD Card.

I have successfully configured the 12 ADC channels using ADC1, ADC2, and ADC3 together in the triple ADC regular simultaneous mode. The ADC1 gets triggered by TIM2. The ADCs are read be DMA2 Stream0 Channel0.

The SD Card is written to using the ST SDIO library in DMA mode. 

I need to write multiple blocks as fast as possible which means I need to use DMA. Polling mode doesn't seem to be implemented in SD_WriteMultiBocks() anyway. I did try to use polling mode with SD_WriteBlock() and that seemed to work ok even with the data acquisition going on. This would indicate that there is something strange going on between the DMA2 stream0 (ADC) and DMA2 stream6 (SDIO).

The thing is that, separately both tasks work perfectly but, when both tasks are active, as soon as the writing to the SD Card begins, the ADC values gets stuck at some random value, the same on all channels.

Another strange behaviour; when data acquisition and storing of data are both active, there seems to be a lot of spurious interrupts arriving to the DMA2 Stream0 Channel0 interrupt handler. This phenomenon starts as soon as the writing to the SD Card starts. It doesn't help to use polling mode for the SDIO either, so I guess it's something with the SDIO port access conflicting with the ADC sampling.

Any ideas as to what can be the cause of this weird behaviour?

#stm32f4-adc-dma-sdio
3 REPLIES 3
frankmeyer9
Associate II
Posted on January 28, 2013 at 15:20

In absence of other details, is it possible that your data flow regime ADC -> DMA -> (some)Buffer -> DMA -> SDIO is too rigid, and doesn't tolerate larger SD write runtimes ?

In this case, you will likely need to improve your buffering strategy..

ulf
Associate
Posted on January 28, 2013 at 15:35

At the moment the two tasks runs independently. The writes to the SD Card is done from a dummy buffer with nonsense data.

I am using the debugger to show the contents of the data that is sampled from the ADC. The debugger also shows the sample count once every second.

The sample count is stable at 30000 per second as long as I don't start any writes to the SD Card. When writing to the SD Card, the reported ADC sample count increases at least tenfold.

frankmeyer9
Associate II
Posted on January 28, 2013 at 17:32

So you are talking basically about effects in the debugger ?

I don't know your hardware & setup (toolchain, debug adapter, etc.), but I wouldn't fixate on that. Your debug data probably need to share bandwith the debugger itself, so this might be misleading. Using some GPIOs and a scope could confirm or rebut your issue.

The sample count is stable at 30000 per second ...

 

You don't have an EOC interrupt, do you ?

In general, I would do as few as possible in interrupts, especially high-frequency one's..

You can check your interrupt regime & frequency with the scope-method, too.