2024-06-05 02:41 AM - edited 2024-06-05 02:44 AM
Hi all,
I'd like to know if is ti possible to have multiple callback for interrupt. Beceause with HAL and CubeMX if I have multiple interrupt, I have only one function for callback
HAL_GPIO_EXTI_IRQHandler
example in stm32f4xx_it.c :
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
/* USER CODE END EXTI0_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(B1_Pin);
/* USER CODE BEGIN EXTI0_IRQn 1 */
/* USER CODE END EXTI0_IRQn 1 */
}
/**
* @brief This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(RFM_INT_Pin);
/* USER CODE BEGIN EXTI4_IRQn 1 */
/* USER CODE END EXTI4_IRQn 1 */
}
So if I want to have specific callback for EXTI4 there is a solution from CubeMx or not ?
Maybe :
void EXTI4_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_IRQn 0 */
My_callback(RFM_INT_Pin);
return;
/* USER CODE END EXTI4_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(RFM_INT_Pin);
/* USER CODE BEGIN EXTI4_IRQn 1 */
/* USER CODE END EXTI4_IRQn 1 */
}
Solved! Go to Solution.
2024-06-05 04:30 AM - edited 2024-06-05 04:33 AM
@SBaro.11 HAL_GPIO_EXTI_IRQHandler is not a callback. It is a library handler of the EXTI interrupts. It then calls your callback that must be named HAL_GPIO_EXTI_Callback.
Some STM32 models can distinguish rising vs falling edge events and thus have two callbacks: HAL_GPIO_EXTI_Falling_Callback and HAL_GPIO_EXTI_Rising_Callback.
Cube and HAL library support only one EXTI callback. If you want anything else, just do what you like, in these callback functions or directly in USER CODE sections of the interrupt handlers.
2024-06-05 02:56 AM
Not all of the EXTI lines have unique interrupts; eg,
As there's only one interrupt, you can only have one handler.
The handler has to determine which of the lines caused the interrupt
2024-06-05 04:30 AM - edited 2024-06-05 04:33 AM
@SBaro.11 HAL_GPIO_EXTI_IRQHandler is not a callback. It is a library handler of the EXTI interrupts. It then calls your callback that must be named HAL_GPIO_EXTI_Callback.
Some STM32 models can distinguish rising vs falling edge events and thus have two callbacks: HAL_GPIO_EXTI_Falling_Callback and HAL_GPIO_EXTI_Rising_Callback.
Cube and HAL library support only one EXTI callback. If you want anything else, just do what you like, in these callback functions or directly in USER CODE sections of the interrupt handlers.
2024-06-05 04:53 AM
You can simply read pin states in the loop and in the interrupt. If the interrupt you read is 0 in the loop, and vice versa, you can find out which pin change triggered the interrupt.