cancel
Showing results for 
Search instead for 
Did you mean: 

Device configuration tool does not generate correct code for LPTIM Clock Mux

EdwinID
Associate

Hi,

uC: STM32G051K8U6, IDE: 1.14.1, MX: 6.10.0-RC9

I tried to generate some low frequency timeout using the LPTIM1 and the internal LSI time source, but it seems the code generator doesn't take in account the chosen option in the "LPTIM1 Clock Mux" selector. It seems it always choses the first option, whick is PCLK. 

I confirmed this, generating the code with different options selected and comparing then using WinMerge. Nothing in the code changed. 

After some searching, I found this function was responsible for initialising the clock source:

void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef* hlptim)
{
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  if(hlptim->Instance==LPTIM1)
  {
  /* USER CODE BEGIN LPTIM1_MspInit 0 */

  /* USER CODE END LPTIM1_MspInit 0 */

  /** Initializes the peripherals clocks
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;

    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }

    /* Peripheral clock enable */
    __HAL_RCC_LPTIM1_CLK_ENABLE();
    /* LPTIM1 interrupt Init */
    HAL_NVIC_SetPriority(TIM6_DAC_LPTIM1_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(TIM6_DAC_LPTIM1_IRQn);
  /* USER CODE BEGIN LPTIM1_MspInit 1 */

  /* USER CODE END LPTIM1_MspInit 1 */
  }

}

And I found out that adding the following line in the user code section solves the problem

/* USER CODE BEGIN LPTIM1_MspInit 0 */
  PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI;
/* USER CODE END LPTIM1_MspInit 0 */

I did multiple tests, including enabling LMTIM1 and LPTIM2 and changing the clock sources in various ways, and it always generated the same output code. It seems there is a bug in the Device Configuration Tool.

If someone could confirm this is the right way to do it, I would appreciate it. Of course it would be nice to see this bug resolved in the upcoming version of the Code Generator. Anyone knows how to submit bugs of this kind?

Thanks,

Edwin

 

1 ACCEPTED SOLUTION

Accepted Solutions
CMYL
ST Employee

Hi @EdwinID 

Thank you for the *.ioc !

I confirm the configuration of LPTIM1 kernel clock is missing the LSI selection of CubeMx, this is a bug that I will escalate to the STM32CubeMx tool to fix it.

According to the generated code, the APB-PCLK clock is used for both the register interface and the LPTIM kernel clock. But, the correct output should add the following line:

/* USER CODE BEGIN LPTIM1_MspInit 0 */
  PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI;
/* USER CODE END LPTIM1_MspInit 0 */

 I let you know when this is fixed.

Best Regards

View solution in original post

4 REPLIES 4
CMYL
ST Employee

Hello @EdwinID 

Thank you for the code. 

Can you share the *.ioc file of the STM32CubeMx project ?

I'm working to reproduce the issue. 

Best Regards 

Hi CMYL,

attached you'll find the *.ioc file.

Regards,

Edwin

CMYL
ST Employee

Hi @EdwinID 

Thank you for the *.ioc !

I confirm the configuration of LPTIM1 kernel clock is missing the LSI selection of CubeMx, this is a bug that I will escalate to the STM32CubeMx tool to fix it.

According to the generated code, the APB-PCLK clock is used for both the register interface and the LPTIM kernel clock. But, the correct output should add the following line:

/* USER CODE BEGIN LPTIM1_MspInit 0 */
  PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI;
/* USER CODE END LPTIM1_MspInit 0 */

 I let you know when this is fixed.

Best Regards

CMYL
ST Employee

Hi @EdwinID,

 

An Bugzilla Ticket 174311 is created for the tracking of this bug.

(PS: Ticket 174311 is an internal tracking number, not accessible by customers and usable for internal tracking).

Thanks again for your question.

Best regards,

Younes