felipesandoval
New member
Hello, I am attempting to read parallel data on GPIO1 using DMA as fast as possible, and wanted to know if there is a way to set the output buffer to somehow be the USB FIFO buffer. My goal is to get continuous data from the GPIO register as fast as possible into the USB buffer. My current implementation is using two buffers on RAM2 as the DMA buffer, switching between them when they get full, and sending them as follows:
The problem is that as I continuously read from the USB buffer, when the buffers switch and are sent over there are glitches in the data, i.e., I believe the time it takes to switch between buffers is too long at the frequencies I am receiving data on the GPIO register (~6MHz).
I'm not sure how else to implement this, as I need continuous data output from GPIO1 to USB.
C++:
// Buffer Definitions
#include BUFFER_SIZE 8192
#include SEND_SIZE BUFFER_SIZE*4 // 4 bytes for 32-bit register
uint32_t bufferA[BUFFER_SIZE] DMAMEM __attribute__ ((aligned(32)));
uint32_t bufferB[BUFFER_SIZE] DMAMEM __attribute__ ((aligned(32)));
uint32_t * currBuff;
// DMA ISR when buffer is full
bool isA = true;
void dma_isr()
{
dma.clearInterrupt();
asm("DSB");
// Switch which buffer DMA uses
uint32_t * prevBuff = currBuff;
currBuff = isA ? bufferB : bufferA;
isA = !isA;
dma.destinationBuffer(currBuff, SEND_SIZE);
dma.enable();
Serial.write((uint8_t*)prevBuff, SEND_SIZE); // Send full buffer to USB
}
The problem is that as I continuously read from the USB buffer, when the buffers switch and are sent over there are glitches in the data, i.e., I believe the time it takes to switch between buffers is too long at the frequencies I am receiving data on the GPIO register (~6MHz).
I'm not sure how else to implement this, as I need continuous data output from GPIO1 to USB.