Problem with GPIO interrupt, MCU ignores the mode selected.
Here's my GPIO setup:
/*Configure GPIO pins : P_H_IN_Pin PCA_INT_Pin P_L_IN_Pin */
GPIO_InitStruct.Pin = P_H_IN_Pin|PCA_INT_Pin|P_L_IN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct);I made a little code that calculates the time in milliseconds between interrupts and output it on the screen. I tested it on timer interrupts and it counts correctly.
Then I set up the PWM generator on a timer that gives 2Hz frequency with variable duty cycle. My reading is 250ms for 50% duty cycle, indicating I get the interrupt on BOTH EDGES! When I change the duty cycle to other values I get 2 interleaved readings, that further confirms I get the interrupt on both edges, because if only falling edge would trigger the interrupt, I would get the same reading no matter what the duty cycle is.
My question is HOW IS IT POSSIBLE? I observe the test signal on oscilloscope. It's a perfect square wave, no artifacts, no noticeable noise or jitter.
The only logical conclusion is I get the interrupt on both edges of the test signal, but why? That kills my application, because I have to measure short impulses repeated over a longer period (it's negative 0-3V3 PP, duty cycle around 5%).
What can be the reason the MCU ignores the GPIO setting and triggers the interrupt also for the rising edge? What should I check and test to further investigate the problem?
My device is STM32H747I-DISCO with TouchGFX application installed. The application seems to be working correctly, because when I provide interrupts from another timer as the impulse source - it measures the correct periods very accurately. The only problem I get is from EXTI line.
I get the interrupt from the HAL_GPIO_EXTI_Callback(uint16_t pin) function. I check the pin number. I also tested it for 2 different pins. Same results. Both inputs are configured to trigger the interrupt on the falling edge, but in both cases I get the interrupts from both edges.
BTW, test signal:
UPDATE:
I started new empty project with the issue isolated.
The new project contained only the PWM generator and the EXTI handler.
It worked. Only falling edge detected.
I downloaded my broken old project again into the same device.
Out of the blue it started to work properly.
This is the craziest thing I've seen. The device was clearly broken. After downloading different software and then again the old software it suddenly started to work.
