2022-01-12 02:40 AM
Hi, is there a reason to implement the HAL function over simply running code inside the IRQ handler.
In my current case I only am incrementing a counter and do not need to demux the line, so I presume not this time, but if I was doing something more involved.
Thanks Oliver
2022-01-12 05:43 AM
Convenience.
If you have multiple interrupts, HAL will call HAL_GPIO_EXTI_Rising_Callback for all of them and you can locate all of your code in the same place. Whereas if you put your code in the actual IRQ handler, you would need to duplicate code in each handler.
2022-01-12 06:49 AM
Cube/HAL will check and clear the interrupt source for you.
JW
2022-01-12 04:30 PM
Merging together all of the EXTI lines in a single function is not a convenience, but a problem because in that common callback function one has to sort out all of them and call the next level handlers from other software modules anyway.
I've found this approach to provide a good balance of convenience and performance:
void EXTI3_IRQHandler(void)
{
if (EXTI->PR1 & EXTI_PR1_PIF3) {
EXTI->PR1 = EXTI_PR1_PIF3;
EXTIHandler_BTNx(BSP_BTN_LEFT);
}
}
void EXTI9_5_IRQHandler(void)
{
uint32_t rPR1 = EXTI->PR1;
EXTI->PR1 = rPR1 & (EXTI_PR1_PIF6 | EXTI_PR1_PIF5);
if (rPR1 & EXTI_PR1_PIF6) {
EXTIHandler_MOTOR_DIAG();
}
if (rPR1 & EXTI_PR1_PIF5) {
EXTIHandler_BTNx(BSP_BTN_RIGHT);
}
}
Put this code in a BSP for the specific board and call from it the functionally specific handlers from other software modules. The "inconvenient and excess" code is just the lines 4 and 12-13, but those are trivial.
2022-01-12 04:49 PM
Looks like it has the potential to clear and miss an interrupt source
This might be safer
EXTI->PR1 = (EXTI_PR1_PIF6 | EXTI_PR1_PIF5) & rPR1;
2022-01-12 04:55 PM
But that's not exactly difficult, and doing all the processing in the IRQ Handler is probably clearer and more transparent. And can be limited to the actual sources rather than the kitchen sink approach HAL/Cube example frequently employ.
2022-01-13 04:51 AM
Right, I figure ideally it's best to do the functionality manually, i've gone with HAL_GPIO_EXTI_Rising_Callback in the end, kind of need rapid and reliable right now, although this means I now have to demux in the function whereas in the IRQ handler I wouldn't have to as the two interrupts would have their own.. somewhat unfortunate side effect of HAL.
2022-01-13 07:46 AM
> although this means I now have to demux in the function whereas in the IRQ handler I wouldn't have to as the two interrupts would have their own.. somewhat unfortunate side effect of HAL.
Eh, a lot of the EXTI interrupt handlers are shared so you may need to demux anyway. For example, the EXTI9_5_IRQHandler handler above or EXTI15_10_IRQHandler.
2022-01-13 12:03 PM
Indeed it can! Thanks! Somehow that shared line case slipped through. I fixed and expanded the original post so that people do not copy a broken example.
Well, this just reassures two things again and again: