Bill Greiman
Well-known member
I would like to use DMA with Teeny 3 ADCs in a mode similar to STM32 "circular" mode. Is there a way to do this?
In STM32 "circular" mode I use a 1024 byte buffer and set up a DMA channel to continuously read the ADC.
The DMA controller produces an interrupt at mid buffer and end of buffer. At end of buffer it restarts at beginning of buffer.
This simple interrupt routine writes a continuous stream of 512 byte blocks to a FIFO.
I have been testing my new exFAT library.
It only requires 6 KB of FIFO on an ebay STM32F103C8 board, which has 20KB of RAM, to log a sequence of ADC channels to an SD at nearly 1MHz.
I would like to go faster on Teensy 3.6 and try SDIO.
In STM32 "circular" mode I use a 1024 byte buffer and set up a DMA channel to continuously read the ADC.
The DMA controller produces an interrupt at mid buffer and end of buffer. At end of buffer it restarts at beginning of buffer.
This simple interrupt routine writes a continuous stream of 512 byte blocks to a FIFO.
Code:
// uint32_t to insure 4-byte alignment.
static uint32_t dmaBuf[2][128];
static uint32_t dmaCount;
static void DMA1_CH1_Event() { static void DMA1_CH1_Event() {
if (fifoCount < FIFO_DIM) {
// memcpy takes 7 microseconds on STM32F103 at 72 MHz.
memcpy(fifoBuf[fifoHead], dmaBuf[dmaCount & 1], 512);
fifoHead = fifoHead < (FIFO_DIM - 1) ? fifoHead + 1 : 0;
fifoCount++;
dmaCount++;
} else {
// Overrun error.
}
}
I have been testing my new exFAT library.
It only requires 6 KB of FIFO on an ebay STM32F103C8 board, which has 20KB of RAM, to log a sequence of ADC channels to an SD at nearly 1MHz.
I would like to go faster on Teensy 3.6 and try SDIO.