cancel
Showing results for 
Search instead for 
Did you mean: 

How to know from which DMA channel HAL_TIM_PWM_PulseFinishedCallback interrupt came from?

HJang.3
Associate II

In STM32F103C8T6 , I am using timer1 channel 1 and channel2 for PWM generation using DMA.

TIM1_CH1 uses DMA1_Channel 2

and TIM1_CH2 uses DMA1_Channel 3.

NOW i am using

full transfer interrupt : HAL_TIM_PWM_PulseFinishedCallback

and half transfer interrupt : HAL_TIM_PWM_PulseFinishedHalfCpltCallback

Now I don't know if these interrupts are called by DMA Ch2 OR Ch3.

Is there a way to know , from which channel is it coming?

my code is:

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
        for(int i = 30 ; i < 60 ; i++){
	int temp1 =1330 - sinebuffer[i-30];
	if(temp1 >0 && temp1< 1333)sinebuffer[i] = temp1;}
}

3 REPLIES 3
Piranha
Chief II

Another HAL failure by design... :D

Apparently you have to look for a pointer to DMA structure at htim->hdma[TIM_DMA_ID_CC1] and compare it to the DMA_HandleTypeDef structure in your code.

Just found a method.

void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim){
 
	if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
        {----}
 
        if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
        {----}
}

where channel 1 is Timer channel number ,Not DMA channel number.

Thank you .