2015-06-30 03:10 AM
Hi,
I used STM32CubeMX to configure Timers 10 and 11 in interrupt mode (Along with FreeRTOS)void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base){ if(htim_base->Instance==TIM11) { /* USER CODE BEGIN TIM11_MspInit 0 */ /* USER CODE END TIM11_MspInit 0 */ /* Peripheral clock enable */ __TIM11_CLK_ENABLE(); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(TIM1_UP_TIM11_IRQn, 5, 0); HAL_NVIC_EnableIRQ(TIM1_UP_TIM11_IRQn); /* USER CODE BEGIN TIM11_MspInit 1 */ /* USER CODE END TIM11_MspInit 1 */ }}I have set the Timer to count UP till 1 second.I am facing a weird issue with the timer interrupts. The timer interrupt hits immediately after the call function toHAL_TIM_Base_Start_IT(&htim11);this happens for both the two timers 10 and 11. I have not investigated this for other times but can anyone throw some light on this behavior?Thanks. #tim10 #stm32f407 #407vg #tim112015-06-30 04:20 AM
Hello samal.mrunmoy.002,
What are you expecting as behavior?In HAL_TIM_Base_Start_IT, the TIM Update interrupt is enabled. You may refer to the example STM32Cube_FW_F4_V1.6.0\Projects\STM32F4-Discovery\Examples\TIM\TIM_TimeBase as a start point.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-07-02 01:33 AM
Hi Mayla,
Thanks for your answer. I guess I didn't post my question correct. I was trying to get an event timeout by using timers and was not able to achieve this because the timer interrupt was getting hit immediately after call the HAL_TIM_Base_Start_IT() function.I expect the timer interrupt to hit after the timer ''expires'' not ''immediately'' after I call the HAL_TIM_Base_Start_IT(). However, was able to figure it out.The URS bit was not set in the CR1 register because of which Update Event was generated and Interrupt Handler was hitting the moment function HAL_TIM_Base_Start_IT() was called.According to Ref. Manual: On setting this bit, only timer overflow will generate the interrupt.Modified the function TIM_Base_SetConfig() function to make it work for my timers/** * @brief Time Base configuration * @param TIMx: TIM peripheral * @param Structure: pointer on TIM Time Base required parameters * @retval None */void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure){ uint32_t tmpcr1 = 0; tmpcr1 = TIMx->CR1; /* Set TIM Time Base Unit parameters ---------------------------------------*/ if(IS_TIM_CC3_INSTANCE(TIMx) != RESET) { /* Select the Counter Mode */ tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); tmpcr1 |= Structure->CounterMode; } if(IS_TIM_CC1_INSTANCE(TIMx) != RESET) { /* Set the clock division */ tmpcr1 &= ~TIM_CR1_CKD; tmpcr1 |= (uint32_t)Structure->ClockDivision; } TIMx->CR1 = tmpcr1;if ((TIMx == TIM10) ||
(TIMx == TIM11) || (TIMx == TIM13) || (TIMx == TIM14)) { TIMx->CR1 |= TIM_CR1_URS; } /* Set the Auto-reload value */ TIMx->ARR = (uint32_t)Structure->Period ; /* Set the Prescaler value */ TIMx->PSC = (uint32_t)Structure->Prescaler; if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET) { /* Set the Repetition Counter value */ TIMx->RCR = Structure->RepetitionCounter; } /* Generate an update event to reload the Prescaler and the repetition counter(only for TIM1 and TIM8) value immediately */ TIMx->EGR = TIM_EGR_UG;}Code added inblue
.Or call __HAL_TIM_URS_ENABLE() macro before the call to TIM_Base_SetConfig() in HAL_TIM_Base_Init() function.Hope someone finds it useful!Thanks.Mrunmoy