AnsweredAssumed Answered

Triggering DMA on a Timer

Question asked by jdcowpland on Sep 10, 2013
Latest reply on May 24, 2015 by PeterLup2
Hi guys,

I'm having a few issues setting of a DMA transfer based on a timer and hoping someone might be able to point out where I'm going wrong. I have a timer (timer 2) which is set to 50 Hz and as far as I can tell, this timer is associated with DMA1 Ch2 if I want to use the Timer2_Update? (Chip is STM32F103ZG). The timer seems to be successfully triggering the DMA, but not at the 50 Hz rate I'm looking for. My timer code looks like this:

void Timer2_config(void){
GPIO_Digital_Output(GPIOF_BASE, _GPIO_PINMASK_ALL);  // Enable digital output on PORTE
GPIOF_ODR = 0;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  RCC_APB1ENR.TIM2EN = 1;
  TIM2_CR1.CEN = 0;
  TIM2_PSC = 72;
  TIM2_ARR = 10000;
 
//TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC2Init(TIM2, &TIM_OCInitStructure);

//NVIC_IntEnable(IVT_INT_TIM2); // Enable timer interrupt
TIM_DMACmd(TIM2, TIM_DMA_CC2, ENABLE);

//TIM2_CR2.CCDS=1;
TIM2_CR1.CEN = 1;
}

Whilst my DMA is configured like this:
void DMA1Config(void){
  /* Configure clock for DMA Controller */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);

  /* Deintialize DMA Channels */
  DMA_DeInit(DMA1_Channel2);

  DMA1_CCR2.EN = 0;

  DMA1_CCR2.DIR_ = 0;                       //READ FROM PERIPHERAL
  DMA1_CCR2.CIRC = 0;                       //CIRCULAR MODE DISABLED (NORMAL MODE)
  DMA1_CCR2.PINC = 0;                       //PERIPHERAL INCREMENT MODE DISABLED
  DMA1_CCR2.MINC = 0;                       //MEMORY INCREMENT MODE DISABLED
  DMA1_CCR2.PSIZE0 = 1;                     //SET PERIPHERAL SIZE TO 16 BITS
  DMA1_CCR2.PSIZE1 = 0;                     //SET PERIPHERAL SIZE TO 16 BITS
  DMA1_CCR2.MSIZE0 = 1;                     //SET MEMORY SIZE TO 16 BITS
  DMA1_CCR2.MSIZE1 = 0;                     //SET MEMORY SIZE TO 16 BITS
  DMA1_CCR2.PL0 = 0;                        //SET CHANNEL PRIORITY HIGH
  DMA1_CCR2.PL1 = 1;                        //SET CHANNEL PRORITY HIGH
  DMA1_CCR2.MEM2MEM = 1;                    //ENABLE MEM2MEM MODE
                        
  DMA1_CNDTR2 = 2;
  DMA1_CPAR2 = (uint32_t)DummyDisplayBuffer;


  NVIC_IntEnable(IVT_INT_DMA1_Channel2);
  DMA1_CCR2.TCIE = 1;
  DMA1_CCR2.EN = 1;
}



The DMA transfer complete interrupt simply toggles an LED so I can see the speed it's transferring at.

Outcomes