2020-05-25 03:23 PM
I'm struggling to find a solution to this by searching.
I have an existing system running using PA1 as an EXTI set up through Cube MX. I just need to add an exrernal interrupt to PA0
As far as I can see the following code is all I should need to add:
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); // IRQ Line0 for new IRQ (Port PA0)
HAL_NVIC_EnableIRQ(EXTI0_IRQn); //Enable IRQ
EXTI->RTSR |= 1; // Enable Rising IRQ Line 0
EXTI->IMR |= 1; //Unmask IRQ Line 0.
My existing callback should suffice for the new IRQ but it doesn't get triggered because the HAL_GPIO_EXTI_IRQHandler() in stm32f1xx_hal_gpio.c doen't run
Could someone let me know what I'm missing?
2020-05-25 05:01 PM
That should call EXTI0_IRQHandler. You'll need to call HAL_GPIO_EXTI_IRQHandler from within there.
2020-05-25 05:05 PM
Also, is PA selected for EXTI0 in SYSCFG?
JW
2020-05-26 03:18 AM
Thanks for that. I see that I am missing the EXTI0_IRQHandler. Should I create this function in stm32f1xx_it.c/h files next to its brother EXTI1_IRQHandler which was generated by MX, or should I put it in main.c or similar? I worry that it may be overwritten or removed by future use of MX.
2020-05-26 03:21 AM
Thanks Jan.
I don't know what SYSCFG is. There doesn't seem to be a file of that name in my project...
2020-05-26 06:11 AM
> Should I create this function in stm32f1xx_it.c/h files next to its brother EXTI1_IRQHandler which was generated by MX, or should I put it in main.c or similar? I worry that it may be overwritten or removed by future use of MX.
CubeMX should generate this for you in stm32f1xx_it.c, if you've enabled the right checkboxes. If not, you can put it and its declaration somewhere within a USER CODE section. Those should be preserved on code regeneration.
2020-05-26 06:20 AM
Thanks for that. As far as I can see it is not possible to just add an EXTI to an existing input using MX. In this case the pin is already used as ETR for a counter timer. If I use MX I think it will force the pin to be a simple input/rising edge EXTI OR an ETR. (I'd love to be wrong.)
2020-05-26 07:02 AM
CubeMX is limiting in this regard, this is often seen here. Any "library" and even more a clicky interface inevitably implement only a fraction of possible functionality of the mcu, the "most usual" functions. If you want anything less usual, you have to program.
Also, you should've been more explicit in saying which family are you using, in the initial post. In the 'F1, this detail is different from all other families, instead of SYSCFG the EXTI selection is in AFIO.
JW
2020-05-26 02:41 PM
Help to add EXTI to a port already in use as ETR input for counter/timer (PA0). CubeIDE on STM31F103
Thanks to waclawek.jan and TDK for your help with this.
The crucial bits of code that worked for me are here.
// Initialise Ext IRQ on PA0 (which is currently in use as external trigger for something else.
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); // IRQ Line0 for clock start IRQ (Port PA0)
HAL_NVIC_EnableIRQ(EXTI0_IRQn); //
EXTI->RTSR |= 1; // Enable Rising IRQ Line 0
EXTI->IMR |= 1; // Unmask IRQ Line 0.
/* AFIO_EXTICR[1-4] IRQ Config Registers need to know GPIO Port (A,B,C etc) and Pin.
No action required here because Reset value just happens to be correct for PA0 on LINE0 */
// This is my callback routine
void EXTI0_IRQHandler(void)
{
__HAL_GPIO_EXTI_CLEAR_IT(1); // "1" (Bit0) is the position in the register for Line0
debug("\n IRQ Detected!\n"); // (debug is my routine to write to a serial port)
// Your code here!
}
I realise all this is very untidy and hope someone will tidy it up for posterity. Running the callback through the same path as the MX geneated interrupts would be more consistent but this way leaves the MX generated include files unaltered
2020-05-26 04:11 PM
> /* AFIO_EXTICR[1-4] IRQ Config Registers need to know GPIO Port (A,B,C etc) and Pin.
> No action required here because Reset value just happens to be correct for PA0 on LINE0 */
Heh, indeed, I didn't realize that... :)
JW