Page 1 of 1

DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Wed Jun 20, 2018 4:15 pm
by elagil
Hello,

I am using the DMA of the STM32F746 to sample half a port of the GPIO (8 bits per transfer, FIFO burst enabled, very high priority) from a parallel port ADC. I sample at a rate of 20 MHz with a system clock of 200 MHz. Transfers directly go to an SDRAM memory area.

The DMA is triggered by the ICU that reacts to a rising edge at a timer pin.

After I finish a DMA transfer (e.g. 32k samples) I transfer the memory content over Ethernet to a PC for evaluation using the TCP protocol with zero-copy (DMA-based). DMA transfers from the GPIO pins are triggered every second and transfers to PC directly happen afterwards, meaning that I have a continuous data stream.

I tested two cases:
1) Ethernet transmission of data disabled:
The DMA sampling works fine and I get all the samples I want from the ADC. I can control the NTDR register at the end of the sampling pulses and it always returns to the initial total transfer count.

2) Ethernet transmission of data enabled:
DMA sampling mostly works but sometimes samples are dropped. The DMA does not react to the trigger and misses data from the ADC. The NTDR register shows some value other than the total transfer count after the sampling pulses.

I have two assumptions as to why this happens:
a) The bus is full by having so many memory accesses
b) The DMA priority for the MAC is higher than for my ADC sampling (I set it to 3) and samples are lost due to the DMA not being active when triggered

I run the latest Chibios 18.

I would be happy to hear your thoughts!
Adrian

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Wed Jun 20, 2018 5:01 pm
by Giovanni
Hi,

It could be bus saturation, try putting your buffers on different SRAMs (different slaves on the matrix)..

Giovanni

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Thu Jun 21, 2018 8:10 am
by elagil
I am not sure how to do that, since I transmit the sampled ADC data itself over TCP. Are there memory regions in SDRAM (above 0xC0000000) that are on different busses? I only use one SDRAM module.

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Thu Jun 21, 2018 10:56 am
by Giovanni
You could move your buffers to an internal SRAM area, it has much higher bandwidth. Do you have enough space in SRAM? alternatively you may try to slow down your sampling rate just to see if the problem goes away.

Giovanni

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Thu Jun 21, 2018 12:26 pm
by elagil
Yes, I will try to sample to SRAM and transfer to SDRAM later. Thanks! SRAM should be large enough.

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Tue Jun 26, 2018 2:20 pm
by elagil
I do not lose samples anymore, as I now use SRAM 1 as my destination for sampling the GPIO. I later push the data to SDRAM.

However, I get corrupt samples (single bytes) that are completely broken. I sample a longer time domain signal to memory and some of it is corrupted.

As you see in the picture I attached, this is a plot of three individual sampled time domain signals (20 MHz sampling rate at 8 bit resolution). After a certain memory index the signal is good again, before it (around 9100) the signal has spikes and dips. I already disabled caching in the SRAM memory region that I use for sampling by means of the MPU.

Do you have an idea how corrupt samples can occur? If I restart my DMA (currently in circular mode, peripheral to memory, automatically incrementing memory address by 8 bit), the glitches go away and come back after some time.

Thanks!

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Tue Jun 26, 2018 4:04 pm
by elagil
The problem seems to be that I transfer the SRAM content to SDRAM with DMA. If I use memcpy(), there are no glitches in the signal.

I use DMA transfer like a memcpy equivalent:

Code: Select all

#define INT_MEM_DMA_STREAM STM32_DMA2_STREAM6

#define DMA_M2M_CONF STM32_DMA_CR_PL(0) | \
                    STM32_DMA_CR_PSIZE_BYTE | \
                    STM32_DMA_CR_MSIZE_BYTE
               
// ...               
       
// The copying operation
void copy(void)
{           
  dmaStartMemCopy(INT_MEM_DMA_STREAM, DMA_M2M_CONF, MEM_FIFO, MEM_SDRAM, count);
  dmaWaitCompletion(INT_MEM_DMA_STREAM);
}


The stream is of course allocated.

Code: Select all

dmaStreamAllocate(INT_MEM_DMA_STREAM, 0, NULL, NULL)


Is there an obvious problem?

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Tue Jun 26, 2018 6:29 pm
by steved
Have you considered memory caching?
If you're transferring everything with DMA, probably best to make sure its disabled on the affected areas, using the MMU.

Re: DMA sampling of GPIO + Ethernet transfer -> sample loss

Posted: Tue Jun 26, 2018 9:28 pm
by elagil
As I say, I am already using the MPU to disable caching for the memory region that I use for sampling.