HAL drivers-> Latest version for L1, F4 families. (25Aug2017,needs further investigation on other families)
HAL configuration-> Timer_x in Input Capture mode.
Modules-> stm32f4xx_hal_tim.c and stm32l1xx_hal_tim.c
Function-> void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) ,
Code->i dont mention the other channels because are the same.
Ref. Man. ->
We can observe that if we have an overcapture after clearing the TIM_IT_CC1, it will occurs inside the HAL_TIM_IC_CaptureCallback as an Input Capture event, because CC1IF is already cleared.
If HAL user implements some code inside HAL_TIM_IC_CaptureCallback(htim) to check for the overcapture flag, It is almost useless because needs to trigger twice to have the overcapture flag set ( once for set the CC1IF and twice to set the CC1OF).
As a further consequence user may clear (by reading the CCR1 or manualy) CC1IF flag inside callback function and lose the overcapture and read ofcourse the wrong captured value, or the interrupt will be retriggered because CC1IF is not cleared inside input callback function by the user.
Conclusion-> Checking for overcapture flag, inside callback function is not a way to catch an overcapture
Possible solutions ->
1.(by the MCD team) To clear the CC1IF flag after the call of HAL_TIM_IC_CaptureCallback(htim) function.
2 (by the users) Do not rely on check the CC1OF inside the HAL_TIM_IC_CaptureCallback. Instead read first the CCR1 data and read immediately after the CC1IF flag to see if set. If set the data is probably from overcapture else is ok.
Comments Ofcourse its posible to have an overcapture flag set before HAL clears the CCIF flag. Only in this case user can handle the situation by reading first the overcapture flag and discard the captured value.