2020-11-24 11:22 AM
Greetings:
I'm using Circular DMA on an STM32F303 for double buffered acquisition of multiple signals: ADC, Quadrature counter (TIM2), etc. I was depending on the Half Transfer (HT) to tell me the 1st half of the buffer was filled, and the Transfer Complete (TC) to tell me the second half of the buffer was filled.
On acquisition from both a TIM counter, and from the ADC, it appears the HT and TC indications are reversed from what I expected.
For example, with a buffer of length 2, the HT indication occurs when the SECOND entry has been written (DMA_CNDTR == 2), and the TC indication occurs when the FIRST entry has been written (DMA_CNDTR == 1). The data being captured is ordered position, and the interpretation of the data also matches what I just wrote.
Based on this, I looked at the HT and TC indications on the ADC, and once again, with a buffer of length 6, the HT indication occurs with its DMA_CNDTR == 6, and the TC indication occurs with its DMA_CNDTR == 3.
The TC and HT indications are thus reversed from what I would expect: I expected HT at 1/2 transfer, and TC when complete, showing full buffer remaining to be filled.
As mentioned above, the data being collected is in accordance with the reversed indications. (I take the difference of the quadrature timer capture to calculate velocity, and the data only makes sense if the HT and TC indications are reversed).
Can someone explain to me where I am going wrong, or what I have misunderstood?
Thank you.
P.S.:
Here is my configuration for the TIM capture:
DMA_InitStructure.DMA_PeripheralBaseAddr = (UINT32)&QUAD_TIMER->CNT;
DMA_InitStructure.DMA_MemoryBaseAddr = (UINT32)dPdT_DMA_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = dPdT_BUF_LENGTH;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
and here is my DMA configuration for the ADC capture:
// source is 32-bit common data register for combined ADC1 & ADC2 results
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &(ADC1_2->CDR);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) ADC_CUR_DMA_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = ADC_CUR_DMA_BUF_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
As I mentioned, all DMA TC and HT indications seem to have this issue.
Solved! Go to Solution.
2020-11-24 11:45 AM
I am SO embarrassed! Turns out the TC and HT indications were being transposed between the ISR and the handler routine.
Please ignore!
2020-11-24 11:45 AM
I am SO embarrassed! Turns out the TC and HT indications were being transposed between the ISR and the handler routine.
Please ignore!