2015-08-11 02:28 AM
Hi,
I'm using DMA with Timer2 input capture to sample the (ch2)rising and (ch1)falling edges of a 250kbps signal. So a bit is 4us long. When running the DMA in normal mode, the values make sense and are synced nicely. It obviously fills up the buffer ofDELTA_SAMPLES
samples then stops. However, I need to run it continuously, but assoon as I change to circular mode, the values are completely whack.void
DMA_ConfigurationRx(
void
)
{
DMA_InitTypeDef DMA_InitStructure;
// TIM2_CH1 & 2 DMA1
DMA_DeInit(DMA1_Channel5);
DMA_DeInit(DMA1_Channel7);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&TIM2->CCR1);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DeltaBufferFalling[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = DELTA_SAMPLES;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
// 32-bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
//DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&TIM2->CCR2);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DeltaBufferRising[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = DELTA_SAMPLES;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
// 32-bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
//DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel7, &DMA_InitStructure);
}
Device: STM32F334R8T6 (on the nucleo)
Frequency: 64MHz, 2 flash wait states
IDE+compiler: SW4STM32 (free eclipse based)
Std Library: V1.1.1 (4 April 2014)STM32F30x Standard Peripherals Library Drivers
#timer #dma #stm32f32015-08-11 03:11 AM
Never mind about this. I think the 250kbps is too quick for the DMA or something. Works fine in circular mode with a slower frequency.
2015-08-11 06:11 AM
Well you have to understand that the data is updated continuously and in the background.
To stop the data changing underneath you, you might want to double up the buffer size, and use the HT and TC interrupts to work on the half that's not active. The length will determine the time you have to process the data. So it's important to stay below that window or move data off to another buffer.