cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_LPTIM_Counter_Start(&hlptim1, 0xFFFF) returns HAL_TIMEOUT in LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK), I would be grateful if any expert can help to solve this problem ?

W.K. Tam
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

Finally, I tested and confirmed that the problem was caused by the clock frequency lower than the signal to be counted. I changed the clock from LSE to HSE. It is working now.

W.K. Tam

View solution in original post

5 REPLIES 5
Imen.D
ST Employee

Hello @W.K. Tam​,

Please share as more details as possible to help you solve your issue.

  • Which device and Cube firmware/version are you using?
  • Did you enable the NVIC interrupt?
  • Share your System Clock setting.
  • Share your code.

Try read out and check the LPTIM1 registers and share the result.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
W.K. Tam
Associate III

Hi Imen,

Thanks for your response.

  • I am using the STM32WL55. At this development stage, I am testing the software using NUCLEO-WL55JC1. The STM32CubeIDE version is 1.11.2.
  • No, I did not enable the NVIC interrupt for lptim1
  • Below please find my system code setting

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure LSE Drive Capability

 */

 HAL_PWR_EnableBkUpAccess();

 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

 /** Configure the main internal regulator output voltage

 */

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /** Initializes the CPU, AHB and APB buses clocks

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS_PWR;

 RCC_OscInitStruct.LSEState = RCC_LSE_ON;

 // RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;

 RCC_OscInitStruct.HSEDiv = RCC_HSE_DIV1;

 // RCC_OscInitStruct.LSIState = RCC_LSI_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK

               |RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1

               |RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)

 {

  Error_Handler();

 }

}

  • The code is too large to share. This part of software is used to count the pulse of LC sensor output for water meter reading. It is developed by referencing the sample code of "Demonstration of LC sensor for gas or water metering based on STM32L073Z-EVAL".

After I commented the following section of code in function HAL_LPTIM_Counter_Start of stm32wlxx_hal_iptim.c, it works.

 /* Wait for the completion of the write operation to the LPTIM_ARR register */

// if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)

// {

//  return HAL_TIMEOUT;

// }

I am not sure whether it has any hidden issues with the code commented.

W.K. Tam

Imen.D
ST Employee

Hi @W.K. Tam​,

Please check if the time internal clock is missing for LPTIM1.

Maybe you have similar issue that reported on github:

STM32L4 LPTIM as pulse counter of intermittent pulses fails when initialising with no pulse · Issue #24 · STMicroelectronics/STM32CubeL4 · GitHub

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hi @Imen.D 

Thanks for your reply. I did try to follow recommendation stated in the github but failed. I keep commenting the section of code as stated in my previous message for continuing our development works. Anyway, it may have unexpected issues for doing that. I need to solve the problem. I would like to check with you whether the LPTIM clock source should be higher frequency than the external trigger signal. As I use LSE 32.768 kHz as the clock source of LPTIM1, the signal to be count is 339 kHz. Is it the cause of problem ? Thanks.

Kind regards,

W.K. Tam

Hi,

Finally, I tested and confirmed that the problem was caused by the clock frequency lower than the signal to be counted. I changed the clock from LSE to HSE. It is working now.

W.K. Tam