title: STM32 TIM DAC and DMA
body: <p>I want to offload the CPU of my STM32G491 by using the DMA function.
  I want to use the Timer 2 (TIM2) to generate four moments where a DMA transfer is needed.
  While doing so I can create two pulses in one period.
  The period, duty cycle, and the delay are adjustable by using the Timer Output Compare functions.</p>
  <pre><code>  int amplitude = 0xFFF;
  
    uint16_t current[] = {0, amplitude, 0, amplitude};
  
    HAL_DAC_Start_DMA(&amp;hdac1, DAC_CHANNEL_1, (uint32_t*) &amp;current[0], sizeof(uint16_t), DAC_ALIGN_12B_R);
    HAL_DAC_Start_DMA(&amp;hdac1, DAC_CHANNEL_1, (uint32_t*) &amp;current[1], sizeof(uint16_t), DAC_ALIGN_12B_R);
    HAL_DAC_Start_DMA(&amp;hdac1, DAC_CHANNEL_1, (uint32_t*) &amp;current[2], sizeof(uint16_t), DAC_ALIGN_12B_R);
    HAL_DAC_Start_DMA(&amp;hdac1, DAC_CHANNEL_1, (uint32_t*) &amp;current[3], sizeof(uint16_t), DAC_ALIGN_12B_R);
  
    HAL_TIM_Base_Start_IT(&amp;htim2);
    HAL_TIM_OC_Start_IT(&amp;htim2, TIM_CHANNEL_1);
    HAL_TIM_OC_Start_IT(&amp;htim2, TIM_CHANNEL_2);
    HAL_TIM_OC_Start_IT(&amp;htim2, TIM_CHANNEL_3);
  </code></pre>
  <p>I don't know how I can connect my timers to initiate the transfer of data from memory to the DAC. I hope you can help me give me a direction in the right way.</p>
  <p>I have set up my timers so that they give a DMA request when the timer has expired.
  <a href="https://i.stack.imgur.com/84HYz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/84HYz.png" alt="I have set up all my timers this way" /></a></p>
  <p>While doing so I can create a kind-of biphasic pulse but only for the positive side. The parameters which are adjustable are the two pulse widths, the interphase interval and the period of this pulse. Note that the negative phase will be positive, so it will output two positive pulses.</p>
  <p><a href="https://i.stack.imgur.com/8F2j7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8F2j7.png" alt="enter image description here" /></a></p>