How to generate callback functions in STM32CubeMx?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-19 2: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.
- Labels:
-
GPIO-EXTI
-
Interrupt
-
STM32CubeMX
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-20 12:15 PM
STM32CubeMX Interrupt & Callback setup:
- Pinout & Configuration - System Core - NVIC – Code Generation – IRQ Handler.
- For some interrupts it may be useful to generate interrupt handler code as examples, then copy to different file and disable the interrupt generation in MX so no clash.
- Project Manager - Advanced Settings - Register Callback (far right of page).
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-20 12:15 PM
STM32CubeMX Interrupt & Callback setup:
- Pinout & Configuration - System Core - NVIC – Code Generation – IRQ Handler.
- For some interrupts it may be useful to generate interrupt handler code as examples, then copy to different file and disable the interrupt generation in MX so no clash.
- Project Manager - Advanced Settings - Register Callback (far right of page).
Paul
