cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX IRQHandler does not clear up interrupts

embedonix
Associate III
Posted on May 28, 2015 at 01:51

Hi all!

I used CubeMX to generate a simple project where there are 3 buttons and 3 leds are connected to my STMF103RBT6. I want to use interrupt, but the code generated by CubeMX is not clearing up any interrupts. Here is the original generated code:

void
EXTI15_10_IRQHandler(
void
)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12));
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13)); 
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14)); 
/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
/* USER CODE END EXTI15_10_IRQn 1 */
}

So I want to do is turn each corresponding LED whenever a button is pressed. Using the code above, only the button on GPIO_PIN_14 works, no matter what, 23 and 13 does not work:

void
EXTI15_10_IRQHandler(
void
)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
if
(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_12) != RESET)
{ 
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12));
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_12);
return
;
}
if
(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13) != RESET)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13));
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_13);
return
;
}
if
(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_14) != RESET)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14));
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_14);
return
;
} 
/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
/* USER CODE END EXTI15_10_IRQn 1 */
}

I tried to lend code from a NOT CubeMX library, but it does not work. What I am endded up with is something like this, but it still does not work! I would be happy if you can point out what am I doing wrong. (I have tested all buttons and leds without using interrupts and they are fine! so I guess the problem is in the IRQHandler). #hal #stm32 #flash #exti15_10_irqhandler-stm32
5 REPLIES 5
takahasi
Associate II
Posted on May 28, 2015 at 06:06

Hi, Try this sample.

---

void EXTI15_10_IRQHandler(void)

{

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);

}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

  if (GPIO_Pin == GPIO_PIN_12) {

    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0,

        HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12));

  }

  else if (GPIO_Pin == GPIO_PIN_13) {

    ...

  }

  ...

}
embedonix
Associate III
Posted on May 28, 2015 at 19:41

Thanks! that seems to work.

But is there a way to find out which GPIO Port has rised that function? 

HAL_GPIO_EXTI_Callback does not have any argument to check against the port as far as I saw.

takahasi
Associate II
Posted on May 29, 2015 at 10:19

That is complicate. Only 1 GPIOx.Pn is selected for EXTIn.

---

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; // contains EXTI_MODE

// if the mode contains EXTI_MODE, HAL_GPIO_Init() set AFIO_EXTICRn

// so only 1 line (GPIOA,B,...) is selected for EXTIn

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
embedonix
Associate III
Posted on June 10, 2015 at 22:13

So is it pointless to check for the pins which raised this event? I mean in the

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

if foe example I want to do 2 different thing with 2 different buttons I have to put these button on separate intterupt groups? e.g. first one in EXTI15_10 and second button in EXTI9_5 ??
takahasi
Associate II
Posted on June 11, 2015 at 02:54

void EXTI9_5_IRQHandler(void)

{

  // GPIO_PIN_5 ~ GPI_PIN9

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);

}

void EXTI15_10_IRQHandler(void)

{

  // GPIO_PIN_10 ~ GPI_PIN15

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);

}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

  if (GPIO_Pin == GPIO_PIN_5) {

    // something

  }

  else if (GPIO_Pin == GPIO_PIN_10) {

    // something

  }

}