2020-09-11 12:44 PM
Configuration Info:
MCU : STM32G030K8
STM HAL Dirve Version : 01.03.00.00
PA4 (GPIO_PIN_4) - Configured to generate interrupt upon detecting a falling edge.
PB5 (GPIO_PIN_5) - Configured to generate interrupt upon detecting a falling edge and rising edge.
External interrupt on PA4 and PB5 belong to group interrupt EXTI4_15_IRQn.
All the other gpio's are either configured to be input or output.
Function Execution Info:
1. Disable interrupt using the API HAL_NVIC_DisableIRQ(EXTI4_15_IRQn).
2. Request manual measurement from a sensor, sensor will pull PA4 pin low once data is ready.
3. Read data and store it. Clear interrupts from sensor side by writing to speific to its registers of sensor.
4. Clear interrupts before enabling them again, using this API __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4).
5. Enable interrupt again using the API HAL_NVIC_EnableIRQ(EXTI4_15_IRQn).
Problem:
After performing #1 to #5 as mentioned above, we see that interrupt handler is invoked by MCU as soon as #5 is executed. This is an undesirable behavior.
At step #3, as soon as we read data from sensor, we are clearing interrupt register is sensor and the PA4 goes high again immediately.
Also, there is no activity on PB5 when this action is performed.
Expected behavior is that, MCU should not invoke interrupt handler since we have made sure to disable interrupt at #1. We suspect this API HAL_NVIC_DisableIRQ(EXTI4_15_IRQn) is not working as expected.
Kindly suggest an alternative for this API or any other inputs will be much appreciated.
2020-09-11 12:52 PM
When it invokes the handler, what bits are set? For PA4 or PA5 or both?
2020-09-11 12:57 PM
None of the bits are set. Either PA4 nor PB5.
If any of the bits were set then it would have been easy to resolve this issue. But based on what I have gather it does not belong to both the pins.
2020-09-11 01:03 PM
I'm not sure if that's the intended behavior or not. Since you're not disabling the interrupt enable bit, the system is still trying to trigger that interrupt but because it's disabled in NVIC, it can't fire until it's re-enabled.
Doubt the problem is in HAL_NVIC_EnableIRQ. The code is easy enough to inspect.
I bet disabling the EXTI interrupt enable bit (in EXTI_IMR) rather than the corresponding NVIC interrupt bit would give the functionality you want.
2020-09-11 01:09 PM
Got it. Thanks for the suggestion.
I am not sure how to do it, let me know look around for it.