title: STM32 DMA from timer count to memory
body: <p>I'm using an STM32H743.  I have an external clock signal coming in on a GPIO pin, and I want to very accurately measure elapsed time between each rising (or falling) edge in the external clock signal.  So I set things up so that TIM4 is triggered by the external clock, and TIM5 is triggered by the internal oscillator.</p>
  
  <p>I wrote an IRQ so that whenever TIM4 triggers, an interrupt runs that captures TIM5's value.  It seems to work OK, but I'm wondering if I can do it through DMA to avoid all the context switching and free up the CPU.  Basically I want to set up a DMA so that each TIM4 event initiates a DMA transfer that copies the TIM5 counter value to a circular buffer somewhere.</p>
  
  <p>I've searched through forums and the DMA documentation but I'm hazy on whether a timer register can be a valid DMA source.  I was thinking maybe I could do something like this:</p>
  
  <pre><code>hDma-&gt;PAR = (uint32_t) &amp;htim5.Instance-&gt;CNT;
  hDma-&gt;M0AR = (uint32_t) myBufferPtr;
  hDma-&gt;NDTR = myBufferSize;
  hDma-&gt;CR |= (uint32_t)DMA_SxCR_EN;
  </code></pre>
  
  <p>But I'm not sure if this can work.</p>
  
  <p>Short version:  Can I use the timer's CNT register as a DMA transfer source?  Would it be a peripheral-to-memory transfer?  Or a memory-to-memory transfer?  Are there other flags I need to make this work? Or is it not possible?  Or is there another STM32 feature that would make it easier to count time between pulses?</p>