AnsweredAssumed Answered

STM32 Stpper Motor (PWM +DMA)

Question asked by Munich85 on Jan 20, 2014
Latest reply on Jan 20, 2014 by Munich85

Hieverybody,

I have aquestion regarding a stepper controller firmware provided by ST.  Actually I do not get the DMA run on my STM32F107!

The capturecontrol toggle mode is working, but no other values are loaded in the ARR byDMA and the DMA1_Channel1_IRQHandler is never called.

I triedanother timer-channel with the corresponding DMA channel, but got the sameresult. Where is my error? I’m happy about every suggestion.

void Stepper_Init(void)
{
 
  GPIO_InitTypeDef GPIO_InitStructure;
  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
   /* GPIOA clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  /* GPIOC clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  /* GPIOB clock enable */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  /* Enable DMA1 clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
   
  RCC_AHBPeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
   
 
  /* GPIOB Configuration:TIM4 Channel1 in Output */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; /*AF Alternate Function*/
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
 
 
  /* ---------------------------------------------------------------
  NVIC Cofig
  --------------------------------------------------------------- */
  /*
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
*/
  NVIC_SetPriorityGrouping(7); /* 0 bits for pre-emption priority 4 bits for subpriority*/
  NVIC_SetPriority(DMA1_Channel1_IRQn, 0x01); /* 0x01 = 0x0 << 3 | (0x1 & 0x7), prority is 0x01 << 4 */
  NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  /* ---------------------------------------------------------------
  TIM2 Configuration: Output Compare Toggle Mode:
  --------------------------------------------------------------- */
  TIM_DeInit( TIM4 );
 
   /* Time base configuration */
  TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
  TIM_TimeBaseStructure.TIM_Period =60000;
  TIM_TimeBaseStructure.TIM_Prescaler = 3; //(Durch 4 Teilen)
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
   
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
  //TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);
 
  /* Output Compare Toggle Mode configuration: Channel4 */
  TIM_OCStructInit( &TIM_OCInitStructure );
  TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_Toggle;
  TIM_OCInitStructure.TIM_Pulse = 0; //When a match is found between the capture/compare register and the counter
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OC1Init(TIM4, &TIM_OCInitStructure);
  TIM_ARRPreloadConfig(TIM4, ENABLE);
 
  /* TIM enable counter */
  TIM_Cmd(TIM4, ENABLE);
 
   
  /* -------------------------------------------------------------------
  DMA1 configuration
  ---------------------------------------------------------------------- */
   
  /* DMA1 channel1 configuration ----------------------------------*/
  DMA_DeInit(DMA1_Channel1);
  DMA_StructInit(&DMA_InitStructure);
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&TIM4->ARR); //(uint32_t)TIM2_BASE + 0x2C; //(uint32_t)TIM2_ARR_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SRC_Buffer_INC;//536870952
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  DMA_InitStructure.DMA_BufferSize = BufferSize;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
   
  /* Enable DMA1 Channel1 Transfer Complete interrupt */
  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
 
  /* Enable DMA1 Channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);
   
  /* Enable TIM4 DMA update request */
  TIM_DMACmd(TIM4,TIM_DMA_Update, ENABLE);
 
}

Outcomes