DMA sampling of GPIO + Ethernet transfer -> sample loss

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

DMA sampling of GPIO + Ethernet transfer -> sample loss

Postby elagil » Wed Jun 20, 2018 4:15 pm

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

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

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

Postby Giovanni » Wed Jun 20, 2018 5:01 pm

Hi,

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

Giovanni

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

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

Postby elagil » Thu Jun 21, 2018 8:10 am

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.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

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

Postby Giovanni » Thu Jun 21, 2018 10:56 am

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

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

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

Postby elagil » Thu Jun 21, 2018 12:26 pm

Yes, I will try to sample to SRAM and transfer to SDRAM later. Thanks! SRAM should be large enough.

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

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

Postby elagil » Tue Jun 26, 2018 2:20 pm

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!
Attachments
Capture.PNG

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

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

Postby elagil » Tue Jun 26, 2018 4:04 pm

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?

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

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

Postby steved » Tue Jun 26, 2018 6:29 pm

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.

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

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

Postby elagil » Tue Jun 26, 2018 9:28 pm

As I say, I am already using the MPU to disable caching for the memory region that I use for sampling.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 13 guests