cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 memory to memory DMA with Timer

JBond.1
Senior

Hi, I am trying to do MemToMem DMA operation on Timer input capture.

My code:

#define BufferSize 1000
uint16_t BUFFER_DATA[BufferSize];
 
TIM_HandleTypeDef htim = htim3;
DMA_HandleTypeDef hdma = hdma_tim3_ch4_up;
uint32_t channel = TIM_CHANNEL_4;
uint32_t dma_cc = TIM_DMA_CC4;
uint32_t dma_id_cc = TIM_DMA_ID_CC4;
 
hdma.Init.Direction = DMA_MEMORY_TO_MEMORY;
 
htim.hdma[dma_id_cc]->XferCpltCallback = TIM_DMACaptureCplt;
htim.hdma[dma_id_cc]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
htim.hdma[dma_id_cc]->XferErrorCallback = TIM_DMAError;
 
/* Enable the DMA channel */
HAL_DMA_Start_IT(htim.hdma[dma_id_cc], (uint32_t)&GPIOC->IDR, (uint32_t)&BUFFER_DATA[0], BufferSize);
 
/* Enable the TIM Capture/Compare 1 DMA request */
__HAL_TIM_ENABLE_DMA(&htim, dma_cc);
 
/* Enable the Input Capture channel */
TIM_CCxChannelCmd(htim.Instance, channel, TIM_CCx_ENABLE);
 
/* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
__HAL_TIM_ENABLE(&htim);

How do I get exact value of (uint32_t)&GPIOC->IDR when timer pin goes low?

Do I need to wait half or full captured interrupt?

Which array element in BUFFER_DATA will be the exact (uint32_t)&GPIOC->IDR value? Or there is no way to tell and I need to loop through BUFFER_DATA and guess?

It seems to me that DMA just copies data to the buffer non-stop and timer just gives me the interupt and thats it, so I need to guess which value do I need to pick from the array, as the timer interupt and DMA are out of sync?

1 ACCEPTED SOLUTION

Accepted Solutions

What STM32 part?

What speed are you clocking/capturing here?

The HT IRQ will fire after BUFFER_DATA[499] has been written TC IRQ after BUFFER_DATA[999]

Yeah, you'll have to come up with a scheme to synchronize, or go fish in the buffer for the signal/pin transitions you want to capture.

The write to the array will beat the TIM3_CC4 IRQ, but you are unlikely to be able to service faster that a few 100 KHz, depending on the core/clock.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

What STM32 part?

What speed are you clocking/capturing here?

The HT IRQ will fire after BUFFER_DATA[499] has been written TC IRQ after BUFFER_DATA[999]

Yeah, you'll have to come up with a scheme to synchronize, or go fish in the buffer for the signal/pin transitions you want to capture.

The write to the array will beat the TIM3_CC4 IRQ, but you are unlikely to be able to service faster that a few 100 KHz, depending on the core/clock.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for explanation its a bit more clear now.

I am using STM32F103 with 72Mhz. If I receive data of 1000 uint16_t values each 200ms will this procesor be able to proces it within 200ms?