cancel
Showing results for 
Search instead for 
Did you mean: 

No capture IT triggered

Gaetan
Associate

Hi,

Something seems to be wrong with STMCubeIDE Version: 1.16.0 Build: 21983_20240628_1741 (UTC) with an STM32G070RBT6. After generation of the code, the Timer code is like this:

  1. /**
  2. * @brief TIM3 Initialization Function
  3. * @param None
  4. * @retval None
  5. */
  6. static void MX_TIM3_Init(void)
  7. {
  8.  
  9. /* USER CODE BEGIN TIM3_Init 0 */
  10. // HAL_TIM_IC_DeInit(&htim3); // GDE
  11.  
  12. /* USER CODE END TIM3_Init 0 */
  13.  
  14. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  15. TIM_MasterConfigTypeDef sMasterConfig = {0};
  16. TIM_IC_InitTypeDef sConfigIC = {0};
  17.  
  18. /* USER CODE BEGIN TIM3_Init 1 */
  19.  
  20. /* USER CODE END TIM3_Init 1 */
  21. htim3.Instance = TIM3;
  22. htim3.Init.Prescaler = 1;
  23. htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  24. htim3.Init.Period = 65535;
  25. htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  26. htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  27. if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
  28. {
  29. Error_Handler();
  30. }
  31. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  32. if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
  33. {
  34. Error_Handler();
  35. }
  36. if (HAL_TIM_IC_Init(&htim3) != HAL_OK)
  37. {
  38. Error_Handler();
  39. }
  40. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  41. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  42. if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  43. {
  44. Error_Handler();
  45. }
  46. sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
  47. sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  48. sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
  49. sConfigIC.ICFilter = 0;
  50. if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
  51. {
  52. Error_Handler();
  53. }
  54. /* USER CODE BEGIN TIM3_Init 2 */
  55. /* USER CODE END TIM3_Init 2 */
  56. }

When we call HAL_TIM_IC_Init() function, the htim->State is already set to HAL_TIM_STATE_READY instead of HAL_TIM_STATE_RESET, so HAL_TIM_IC_MspInit(htim) is never called.

So the interrupt is not triggered, HAL_TIM_IC_CaptureCallback() is never called too.

Is my analysis right?

1 ACCEPTED SOLUTION

Accepted Solutions

I've solved the problem.

The MX_NVIC_Init() function called in main does the same thing as the HAL_TIM_IC_MspInit() function, but without testing htim->State.

With the correct NVIC initialization:


/* TIM3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);


Now it's OK.
Thanks for your help.

View solution in original post

2 REPLIES 2
TDK
Guru

htim3 is zero-initialized at the start, which sets its state to HAL_TIM_STATE_RESET. Must be something else going on here. Perhaps show your full main.c code. You could set a watchpoint on htim->State to see where it's being modified.

 

Edit: Oh, I see it gets set to READY in HAL_TIM_Base_Init. Yeah, you may be right. Sorry for noise.

If you feel a post has answered your question, please click "Accept as Solution".

I've solved the problem.

The MX_NVIC_Init() function called in main does the same thing as the HAL_TIM_IC_MspInit() function, but without testing htim->State.

With the correct NVIC initialization:


/* TIM3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);


Now it's OK.
Thanks for your help.