cancel
Showing results for 
Search instead for 
Did you mean: 

I am looking for help with DMA channel memory to a peripheral for a timer.

JKopa.1
Associate II

I am not sure how to handle DMA channel from memory to peripheral. I have a circular buffer of 2*24 words that I want to load to PWM. I want to update(generate) new values once half and top of the buffer is reached. I was using similar thing for ADC to Memory. That was working. But I am unable to figure it out for this case. Any advice link for an example would be appreciated.

3 REPLIES 3

Which STM32?

Basically

  • set up a timer for PWM, i.e. set appropriately TIMx_ARR, TIMx_CCRx, appropriate fields in TIMx_CCMRx and enable in TIMx_CCERx; if it's Advanced timer don't forget to set TIMx_BDCR.MOE
  • in TIMx_CCMR, set also Output compare x Preload Enable
  • set TIMx_DIER.UDE
  • in appropriate DMA Channel/Stream, set whatever is needed so that that stream is tied to given timer's Update, set up source (memory) and destination (TIMx_CCRx) pointers, set appropriate number of transfers into NDTR/CNDTR, in CR/CCR set up the fields to transfer from memory to peripheral, enable the TC and HT interrupts and enable the Channel/Stream
  • write an appropriate interrupt handler for the given DMA Channel/Stream
  • in memory, set up an array of values for the TIMx_CCRx
  • enable timer by setting TIMx_CR.CEN

For Cube, there are probably examples for this in the respective Cube example directory, e.g. https://github.com/STMicroelectronics/STM32CubeL4/tree/master/Projects/STM32L476G-EVAL/Examples/TIM/TIM_DMA

JW

JKopa.1
Associate II

Superb I am on it. And yes ,my fault that I did not wrote that I am working with cube. I will let all know If I will manage. Thanks a lot.

JKopa.1
Associate II

It does not seem to solve my question. Which should most probably be_ how to write an appropriate interrupt handler for the given DMA Channel/Stream.