2025-07-12 9:34 PM - last edited on 2025-07-14 4:25 AM by Andrew Neil
Hello,
I am trying to build a api in stm32 cube ide with base mcu as nucleo board.i am planning to build a api with input parameters GPIO_PIN,IRQ_HANDLER_FUN.
UserAPI_exticf(GPIO_PIN,IRQ_HANDLER_FUNC)
{}
I don't want ot configure gpio as exti in .ioc file and use it main c
I want everythibg to be done in UserAPI_exticfg.
If you have such reference code or libraries please share it.
2025-07-12 10:54 PM
LL_EXTI_SetEXTISource(LL_EXTI_EXTI_PORTB, LL_EXTI_EXTI_LINE11);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_11);
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_11);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_11);
HAL_NVIC_SetPriority(EXTI11_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI11_IRQn);
some inspiration as you can see your func require port info too.
2025-07-14 4:29 AM
@MM..1 wrote:your func require port info too.
@Alex_reynold Will also need the EXTIxxx_IRQn
You haven't said what STM32 you're targetting, but there isn't a 1:1 relationship between Pin number and EXTI line
2025-07-14 5:37 AM - last edited on 2025-07-14 6:02 AM by Andrew Neil
Dear @Andrew Neil ,
I am using a sensor which generate a interate upon anew event.
I am building api to fetch data from sensor upon reading interrupt.this avoids unnecessary polling.
You want to suggest like this??
UserAPI_exticf( GPIO_PORT, GPIO_PIN, IRQ_HANDLER_FUNC )
{
}
Edited to apply source code formatting - please see How to insert source code for future reference.
2025-07-14 5:39 AM
And one more query,here in stm32,isr handler names are already declared but not defined.
Can we write own handler and over ride this pre declared handler.this avoids fetching and declared api and definibg
2025-07-14 6:08 AM
@Alex_reynold wrote:in stm32, isr handler names are already declared but not defined.
They are already defined - but the default definition does nothing.
The default definitions are "weak" - meaning that any other definition will override them; eg,
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
(See the startup_stm32xxx.s file for your project)
So you make your own definitions, and they override those default, empty definitions.
2025-07-14 6:13 AM - edited 2025-07-14 6:21 AM
@Alex_reynold wrote:You want to suggest like this??
UserAPI_exticf( GPIO_PORT, GPIO_PIN, IRQ_HANDLER_FUNC )
As I said, you would also probably need the EXTI IRQ number as a parameter - because there is no not necessarily a direct mapping from GPIO port+pin to the EXTI IRQ number; eg,
UserAPI_exticf( gpio_port, gpio_pin, irq_n, irq_handler )
EDIT Correction: Whether there is a direct mapping from Pin number to EXTI_IRQn depends on the used STM32 - which is still not known.