2022-01-19 02:22 PM
Hi,
I am configuring an IO is GPIO_EXTI. I can't figure out how to generate the callback function. I looked into example projects and I saw this function. HAL_GPIO_EXTI_Callback definitely looks like something generated by CubeMX. I would like to understand how to generate such callback functions.
Thanks.
Solved! Go to Solution.
2022-01-20 12:15 PM
STM32CubeMX Interrupt & Callback setup:
- Pinout & Configuration - System Core - NVIC – Code Generation – IRQ Handler.
- Project Manager - Advanced Settings - Register Callback (far right of page).
Paul
2022-01-19 11:54 PM
The callback functions are already defined in the HAL or LL library with the __weak attribute:
/**
* @brief EXTI line detection callback.
* @param GPIO_Pin: Specifies the port pin connected to corresponding EXTI line.
* @retval None
*/
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(GPIO_Pin);
/* NOTE: This function should not be modified, when the callback is needed,
the HAL_GPIO_EXTI_Callback could be implemented in the user file
*/
}
In the library, the function is created as an empty function, so to speak, so that the linker does not throw an error. If you want to use such a function, you only need to define it in your code, e.g. in main.c - but without the __weak attribute, just like you showed in your screenshot.
You can find the basics of __weak in various places on the web, e.g. on Wikipedia. The use in the HAL or LL library is described in the user manual of the library of the respective STM32 family - just search for "description hal low" on st.com.
Good luck!
Regards
/Peter
2022-01-20 12:15 PM
STM32CubeMX Interrupt & Callback setup:
- Pinout & Configuration - System Core - NVIC – Code Generation – IRQ Handler.
- Project Manager - Advanced Settings - Register Callback (far right of page).
Paul