cancel
Showing results for 
Search instead for 
Did you mean: 

What is the cause of LPTIM_WaitForFlag function resulted HAL_TIMEOUT in STM32WL MCU ?

W.K. Tam
Associate III

I modified the LoRaWAN_End_Node sample program for measuring the external pulses input to the COMP1. I register a task in the sequencer and set up the timer in timer server. It is no problem to run a test task by just toggle the LED. When I initialize the lptim1 timer to count the external pulse, the program jump to the while(1) loop in Error_Handler. Checking by breakpoints, it is because the LPTIM_WaitForFlag function resulted HAL_TIMOUT. Below is the code of lptim1 initialization.

void LPTIM1_Init(void)
{
hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim1.Init.UltraLowPowerClock.Polarity = LPTIM_CLOCKPOLARITY_RISING;
hlptim1.Init.UltraLowPowerClock.SampleTime = LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_6;
hlptim1.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_RISING;
hlptim1.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_EXTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_COMP1;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
{
Error_Handler();
}
// Start Counting
if (HAL_LPTIM_Counter_Start(&hlptim1, 0xFFFF)!= HAL_OK)
{
Error_Handler();
}
// lptim1 enable
hlptim1.Instance->CR |= 0x00000001;

// lptim1 continuous mode
hlptim1.Instance->CR |= 0x00000004;
}

I would be grateful if any expert can help to solve the problem.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
IIRHO.1
ST Employee

Hello @W.K. Tam and welcome to ST Community.

I suggest you to:

  • Make sure that LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC is the correct clock source.
  • Make sure that LPTIM_PRESCALER_DIV1 is the correct value for your application.
  • Make sure that LPTIM_INPUT1SOURCE_COMP1 is the correct input source for your application.
  • Make sure that LPTIM_TRIGSOURCE_6 is the correct trigger source.
  • Make sure that the external pulse input is connected and functioning as expected.

Also, you can try to increase the timeout value for LPTIM_WaitForFlag to see if that resolves the issue.

I hope this is helpful for you.

Issam

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

3 REPLIES 3
IIRHO.1
ST Employee

Hello @W.K. Tam and welcome to ST Community.

I suggest you to:

  • Make sure that LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC is the correct clock source.
  • Make sure that LPTIM_PRESCALER_DIV1 is the correct value for your application.
  • Make sure that LPTIM_INPUT1SOURCE_COMP1 is the correct input source for your application.
  • Make sure that LPTIM_TRIGSOURCE_6 is the correct trigger source.
  • Make sure that the external pulse input is connected and functioning as expected.

Also, you can try to increase the timeout value for LPTIM_WaitForFlag to see if that resolves the issue.

I hope this is helpful for you.

Issam

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.

Hi @IIRHO.1 ,

Thanks for your help. I solved the problem by using STM32cubeMX to initialize the lptim. My problem may be caused by COMP1 which is not connected to the DAC input properly. Anyway, using STM32cubeMX to do the setting, it works well.

Thanks,

W.K. Tam

Hello again and thank you for your feedback.

If your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.

Issam

 

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.