Apparent minor bug in HAL_TIM_IRQHandler()
There appears to be a minor bug in HAL_TIM_IRQHandler(), in stm32f7xx_hal_tim.c
APPARENT-BUG SUMMARY:
There's a line-of-code that works, but I think it's just by coincidence:
For a "TIM Update event", the TIMx_SR register's UIF bit is cleared using the mask for the TIMx_DIER register's UIE bit.
The mask for the TIMx_SR register's UIF bit should be used, instead.
Both masks are used to set bit 0, so the code works.
Using the wrong mask is confusing to the reader.
__HAL_TIM_CLEAR_IT() is used to clear the bit.
The file's other calls to __HAL_TIM_CLEAR_IT() may also have this same type of bug.
DESCRIPTION:
In the code section "TIM Update event" (shown below), this line:
__HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
should be:
__HAL_TIM_CLEAR_IT(htim, TIM_FLAG_UPDATE);
These macros are defined in stm32f7xx_hal_tim.h:
#define TIM_IT_UPDATE TIM_DIER_UIE /*!< Update interrupt */
#define TIM_FLAG_UPDATE TIM_SR_UIF /*!< Update interrupt flag */
#define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
The code is intended to clear the TIMx_SR register's field: Bit 0 UIF: Update interrupt flag.
So, TIM_FLAG_UPDATE should be used, not TIM_IT_UPDATE.
The file's other calls to __HAL_TIM_CLEAR_IT() may also have the same type of bug, e.g.,
__HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
/* TIM Update event */
if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
{
if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET)
{
__HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
htim->PeriodElapsedCallback(htim);
#else
HAL_TIM_PeriodElapsedCallback(htim);
#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
}
}