cancel
Showing results for 
Search instead for 
Did you mean: 

Can somebody help me here. Interrupt handler routine is not getting Exit. Context Switch Not working back to the main task.

Vmere.1
Senior

Hello,

Technical Details:

  1. CMSIS- RTX based RTOS.
  2. STM32H7xx based MCU.

Problem Description:

I am trying to find the duty cycle of a incoming PWM. And my problem occurs when there is an interrupt and now the interrupt handler executes properly but It doesn't come back to the main task (os based). I am not getting hard fault or any kind of trouble. Where do you think I made a mistake.

Code of interrupt handler

void TIM2_IRQHandler(void)

{

TIM_HandleTypeDef * sWorkingLight_psTim;

sLight_psTim = APPLICATION_TIM_psGetHandleTim_LIGHT();

  HAL_TIM_IRQHandler(sWorkingLight_psTim);

}

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

static UL_32 IC_val1 = 0;

static UL_32 IC_val2 = 0;

static UW_16 is_first_captured = 0;

if((htim->Instance == WORKING_LIGHT_TIMER_INTERFACE)&& (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4))

{

if(is_first_captured == 0)

{

__HAL_TIM_SET_COUNTER(htim, 0);

is_first_captured = 1;

__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_CHANNEL_4, TIM_INPUTCHANNELPOLARITY_FALLING);

}

else if(is_first_captured == 1)

{

IC_val1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);

is_first_captured = 2;

__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_CHANNEL_4, TIM_INPUTCHANNELPOLARITY_RISING);

}

else if(is_first_captured == 2)

{

IC_val2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);

duty_cycle = IC_val1 * 100/ (IC_val2 + 0.1);

//HAL_NVIC_DisableIRQ(WORKING_LIGHT_TIM_IRQn);

is_first_captured = 0;

}

}

}

//--------------------------------------------------------------------------------------------------

when I check the value of duty cycle I can read the expected value but it is not coming back from irq handler.

6 REPLIES 6
Mike_ST
ST Employee

>> void TIM2_IRQHandler(void)

>> {

>> TIM_HandleTypeDef * sWorkingLight_psTim;

>> sLight_psTim = APPLICATION_TIM_psGetHandleTim_LIGHT();

>> HAL_TIM_IRQHandler(sWorkingLight_psTim);

>> }

The sWorkingLight_psTim is pointing to nothing.

I guess it should be intialized thanks to the second line, which is not the case as is.

hello mike,

I changed it but still not working

void TIM2_IRQHandler(void)

{

TIM_HandleTypeDef * sWorkingLight_psTim;

sWorkingLight_psTim = APPLICATION_TIM_psGetHandleTim_WORKING_LIGHT();

if(__HAL_TIM_GET_FLAG(sWorkingLight_psTim, TIM_IT_CC4) == SET)

{

 __HAL_TIM_CLEAR_IT(sWorkingLight_psTim, TIM_IT_CC4);

HAL_TIM_IRQHandler(sWorkingLight_psTim);

}

}

It's really not necessary to like one's own posts

You should check what's still flagging, or what's going on at such at rate that you can't clear the service routine before the next comes along.

Figure the saturation point is a few hundred KHz, especially dragging the HAL and callback stuff along for the ride.

Tail-chaining will keep the MCU in interrupt context for as long as something is pending.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi again,

If I remember well the HAL_TIM_IRQHandler(); doesn't expect that you check/clear for flags before calling it or the callback won't be called.

Vmere.1
Senior

Hey, I didn't understand what you said? You mean to try with different frequencies?0693W00000GWqAaQAL.pngBut this is the latest screenshot

But callback is not issue for me. Returning to main is the issue. The callback is working well. I was able to set breakpoint and check. But not going to main again.