Measure time between two GPIO events in STM32
The short answer is: you need to use the Timer in input capture mode!

Then Timer_Pin can be configured for external interrupt trigger i.e when an external interrupt occurs then an input time capture(~time stamp) occurs. Similarly, another capture occurs at the next interrupt, you just need to find the difference between the two captures to calculate the time elapsed between two events. But care has to be taken in configuring the Timer so that it can capture at least two consecutive interrupts!

To explain things further, I am assuming that you are using STM32CubeMx to generate the code, even if you are not the similar steps can be followed!


You need to configure a Timer in "Input Capture Direct mode", that assigns a GPIO pin to it. Now, you can use this for your sensor interrupt!
Configure the timer such that it should be able to capture a minimum of two consecutive TIM captures. 


The calculation is simple and goes as follows-

The minimum frequency that you measure is

MinPulseFrequency = (2*TIMxPeripheralFrequency)/((Period+1)(Prescaler+1)) 



Go through STM32Cube Examples and look for TIM/Timer_Input_Capture example. It has been explained fairly good.
Even if you don't want to go through complete details on how all Timer modes work, make sure that you understand what is happening in input capture mode! and see how it can be configured properly using this General Purpose Timer Cookbook.


For similar problem in a different context but which works as an example code for you will be this post.