cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 clock source disabld but timer still running correctly?

Ricko
Senior II

Hi,

as you can see from the screenshot below I have TIM2 clock source set to disable but the PWM is still running as configured and generates PWM. And it has been like that for the entire project for a while so I just noticed.

Does the time start function automatically select the source to some default like the Internal clock? Or is that Clock source referring to something else? Just asking because I want to make sure the code is running correctly for the right configuration not because of some other settings that somehow override these.

Thank you

 

Ricko_0-1726436375212.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

When Clock source is disabled, HAL_TIM_ConfigClockSource() is not generated and when "Internal Clock" is selected, the following code is generated:

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }

And according to HAL_TIM_ConfigClockSource() implementation TIM_CLOCKSOURCE_INTERNAL does almost nothing, just some bit reset before: 

  /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
  tmpsmcr = htim->Instance->SMCR;
  tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
  tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
  htim->Instance->SMCR = tmpsmcr;

  switch (sClockSourceConfig->ClockSource)
  {
    case TIM_CLOCKSOURCE_INTERNAL:
    {
      assert_param(IS_TIM_INSTANCE(htim->Instance));
      break;
    }

So "Internal Clock" and "Disable" seems to have the same behavior.

 

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.

View solution in original post

1 REPLY 1
SofLit
ST Employee

Hello,

When Clock source is disabled, HAL_TIM_ConfigClockSource() is not generated and when "Internal Clock" is selected, the following code is generated:

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }

And according to HAL_TIM_ConfigClockSource() implementation TIM_CLOCKSOURCE_INTERNAL does almost nothing, just some bit reset before: 

  /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
  tmpsmcr = htim->Instance->SMCR;
  tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
  tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
  htim->Instance->SMCR = tmpsmcr;

  switch (sClockSourceConfig->ClockSource)
  {
    case TIM_CLOCKSOURCE_INTERNAL:
    {
      assert_param(IS_TIM_INSTANCE(htim->Instance));
      break;
    }

So "Internal Clock" and "Disable" seems to have the same behavior.

 

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.