2023-06-29 05:04 AM - edited 2023-06-29 05:04 AM
Not sure where to post a HAL bug report so posting here. Am using STM32F407zet6 in STM32CubeIDE latest version.
The MX_TIMx_Init function generated by codegen causes a trigger event to occur for the timer. This means that if a timer is set to trigger in response to update from another timer then it will prematurely start during the codegen TIMx_Init functions if it was initialised before the master. This essentially means that successful timer synchronization when update is used as the trigger depends on the ordering of the MX_TIMx_Init codegen function calls.
The reason for the trigger event is as follows:
Let's say TIM1 is the slave and TIM4 is the master (As in my code):
As you can see from the above, this issue means timer slave triggering can happen during the initialisation of timers, rather than when they are started (As seems is the expected behaviour), if they are initialized in an unfavourable order. It would be great if this can be fixed in the HAL so that others do not run into the same issue. As a workaround for now I'm planning to try within "/* USER CODE BEGIN TIM4_Init 1 */" setting the MMS bits to 100 (OC1REF) or some other value which will not be triggered by "TIMx->EGR = TIM_EGR_UG;".
2023-06-29 05:32 AM - edited 2023-06-29 05:33 AM
Adding the following 2 lines to TIM_Base_SetConfig in stm32f4xx_hal_tim before "TIMx->EGR = TIM_EGR_UG;" does workaround the issue, but I dont think this is compatible with codegen:
/* Reset the MMS Bits */
TIMx->CR2 &= ~TIM_CR2_MMS;
/* Select the TRGO source to one which will not occur during HAL_TIM_Base_Init */
TIMx->CR2 |= TIM_TRGO_OC1REF;
Hopefully can find another workaround compatible with codegen (Attempting to write to the CR2 register before this point within "USER CODE BEGIN TIM4_Init" does not succeed in writing to the register)
2023-06-29 05:39 AM
Discovered the github and posted an issue there:
https://github.com/STMicroelectronics/STM32CubeF4/issues/157