2019-08-22 07:55 AM
In the sample code, STM uses "HAL_GPIO_EXTI_Callback" to handle interrupt from a push button, but in class I learnt that we need to use the IRQHandler to handle the interrupt. When to use "HAL_GPIO_EXTI_Callback" and "HAL_GPIO_EXTI_IRQHandler" to handle interrupt?
Solved! Go to Solution.
2019-08-22 09:08 AM
The IRQ Handler is the thing that actually gets called by the NVIC, you then call into the HAL via HAL_GPIO_EXTI_IRQHandler(), and then it in turn calls your callback functions if it validates a specific source, it also then clears the source as it leaves.
HAL just layers on some extra complexity, you can chose to use or ignore that if you wish.
/**
* @brief This function handles external line 15_10 interrupt request.
* @param None
* @retval None
*/
void EXTI15_10_IRQHandler(void) // << Processor goes here via Vector Table
{
HAL_GPIO_EXTI_IRQHandler(USER_BUTTON_PIN); // >> Goes INTO HAL here, and then out to your callback
}
2019-08-22 09:08 AM
The IRQ Handler is the thing that actually gets called by the NVIC, you then call into the HAL via HAL_GPIO_EXTI_IRQHandler(), and then it in turn calls your callback functions if it validates a specific source, it also then clears the source as it leaves.
HAL just layers on some extra complexity, you can chose to use or ignore that if you wish.
/**
* @brief This function handles external line 15_10 interrupt request.
* @param None
* @retval None
*/
void EXTI15_10_IRQHandler(void) // << Processor goes here via Vector Table
{
HAL_GPIO_EXTI_IRQHandler(USER_BUTTON_PIN); // >> Goes INTO HAL here, and then out to your callback
}