I'm trying to respond to an IRQ in the fastest way possible on an STM32F04. Configuring a GPIO as EXTI works, but there's a ~200ns delay even at highest priority, presumably due to the overhead of the IRQ and calling the handler. The documentation suggests up to 12 clock cycles are required, which should be ~70ns at 168MHz?
I don't mind polling for the IRQ in my main loop - the micro isn't doing anything else, and this does work with very small delay (~20ns or so) provided the pin is configured as GPIO_INPUT and not as EXTI. However, the pulse width of the IRQ is only ~20ns so it sometimes misses it if I'm just reading the pin in a loop (~1 in 10). Given the short pulse I expect this to happen, but I want to know what alternatives I might have besides using some circuitry to extend the pulse duration.
I had the idea to use a timer as a counter for the IRQ pulses, which I can then check in my main loop. If I received 1 count, then I perform the required behaviour, and if I see 2+ counts then obviously I have missed an IRQ but can be aware of this. However, I am at a total loss how to configure the timer in this way. Do I configure the timer for "Input capture" mode using my IRQ as the pin? Or do I configure it for "external clock" taking the clock source as my IRQ line?
Or can I somehow speed up my IRQ response? I need it to be <100ns. I'm running at 168MHz with the peripheral clocks set at max speeds. Using HAL/CubeMX.