2019-04-17 09:52 AM
I'm using an STM32F769 for a project. I'm trying to continuously stream ADC samples to a buffer. I can fill the buffer without issue, but the DMA never recirculates back to the beginning. I don't get any DMA errors, and the ADC is still running (I can see the DR value change in the debugger if I halt).
Any ideas? The DMA configuration is below.
// Intermediate buffers for DMA streaming.
static struct tag_sample_buffer {
uint16_t samples[2][1024];
} sampleBuffer[3];
DMA_InitTypeDef dmaInit;
dmaInit.Direction = DMA_PERIPH_TO_MEMORY;
dmaInit.PeriphInc = DMA_PINC_DISABLE;
dmaInit.MemInc = DMA_MINC_ENABLE;
dmaInit.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
dmaInit.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
dmaInit.Mode = DMA_CIRCULAR;
dmaInit.Priority = DMA_PRIORITY_HIGH;
dmaInit.FIFOMode = DMA_FIFOMODE_DISABLE;
dmaInit.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
dmaInit.MemBurst = DMA_MBURST_SINGLE;
dmaInit.PeriphBurst = DMA_PBURST_SINGLE;
hDma[0].Init = dmaInit;
hDma[0].Instance = DMA2_Stream0; // stream for ADC1 event
hDma[0].Init.Channel = DMA_CHANNEL_0; // channel for ADC1 event
HAL_DMA_Init(&hDma[0]);
... ADC config, immaterial
// Associate the initialized DMA handle to the ADC handle:
__HAL_LINKDMA(&hAdc[0], DMA_Handle, hDma[iAdc]);
// Configure the NVIC for the DMA transfer complete interrupt.
HAL_NVIC_SetPriority(DMA_IRQS[0], ADC_DMA_GRP, ADC_DMA_PRIO);
HAL_NVIC_EnableIRQ(DMA_IRQS[0]);
// Start the ADC and DMA. It will wait for the trigger timer.
result = HAL_ADC_Start_DMA(
&hAdc[iAdc],
(uint32_t*) sampleBuffer[iAdc].samples[0],
_countof(sampleBuffer[iAdc].samples)
);
assert(result == HAL_OK);
Thanks,
Bill
Solved! Go to Solution.
2019-04-17 10:17 AM
I don't understand the Cube/HAL gobbledygook, but maybe you want to read the Using the DMA subchapter of ADC chapter in RM, concentrating on the description of function of ADC_CR2.DDS bit. Note, that there's also a DDS bit in ADC_CCR, for multi-ADC mode.
JW
2019-04-17 10:17 AM
I don't understand the Cube/HAL gobbledygook, but maybe you want to read the Using the DMA subchapter of ADC chapter in RM, concentrating on the description of function of ADC_CR2.DDS bit. Note, that there's also a DDS bit in ADC_CCR, for multi-ADC mode.
JW
2019-04-17 11:05 AM
Jan,
That was exactly it. I had spent hours debugging the DMA part of the code, without realizing the DDS bit misset in the ADC configuration section. Thank you.
Regards,
Bill