cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER with DMA call back function

NPULI.1
Associate II

Hi,

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

 if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)

 {

  captureDone = 1;

 }

}

HAL_TIM_IC_Start_DMA(&htim2, TIM_CHANNEL_1, (uint32_t*) captures, 2);

void HAL_TIM_IC_MspInit(TIM_HandleTypeDef* htim_ic)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(htim_ic->Instance==TIM2)

 {

 /* USER CODE BEGIN TIM2_MspInit 0 */

 /* USER CODE END TIM2_MspInit 0 */

  /* Peripheral clock enable */

  __HAL_RCC_TIM2_CLK_ENABLE();

  __HAL_RCC_GPIOA_CLK_ENABLE();

  /**TIM2 GPIO Configuration

  PA0/WKUP   ------> TIM2_CH1

  */

  GPIO_InitStruct.Pin = GPIO_PIN_0;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* TIM2 DMA Init */

  /* TIM2_CH1 Init */

  hdma_tim2_ch1.Instance = DMA1_Stream5;

  hdma_tim2_ch1.Init.Channel = DMA_CHANNEL_3;

  hdma_tim2_ch1.Init.Direction = DMA_PERIPH_TO_MEMORY;

  hdma_tim2_ch1.Init.PeriphInc = DMA_PINC_DISABLE;

  hdma_tim2_ch1.Init.MemInc = DMA_MINC_ENABLE;

  hdma_tim2_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;

  hdma_tim2_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;

  hdma_tim2_ch1.Init.Mode = DMA_CIRCULAR;

  hdma_tim2_ch1.Init.Priority = DMA_PRIORITY_LOW;

  hdma_tim2_ch1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

  if (HAL_DMA_Init(&hdma_tim2_ch1) != HAL_OK)

  {

   Error_Handler();

  }

  __HAL_LINKDMA(htim_ic,hdma[TIM_DMA_ID_CC1],hdma_tim2_ch1);

 /* USER CODE BEGIN TIM2_MspInit 1 */

 /* USER CODE END TIM2_MspInit 1 */

 }

}

I am using embOS, I am not able to enter into call_back function

I am not able to generate the interrupt for the input capture

Regards,

Shashi

1 REPLY 1

Which STM32?

In debugger, read out and check the TIM registers - check if it runs at all, if it has enabled the respective flags in DIER. Then check the NVIC registers if the respective interrupt is enabled. In DMA, check if the respective channel/stream is enabled and if its NDTR is changing as the timer runs. Check in its control register if the respective interrupt is enabled, and then in NVIC again if the respective interrupt is enabled. Check the ISR names, if they match those in the vector table - this is easiest to check in disasm, by checking if the vector table contains proper vectors to ISR at the respective position.

JW