Skip to main content
Strooom
Senior
April 11, 2023
Question

How to use LPTIM_TimeOut for a simple one-shot delay ?

  • April 11, 2023
  • 3 replies
  • 6607 views

I'm trying to realize some simple timings/delays in my application using the LPTIM, and although most of it is working, I don't understand it 100%.

So the LPTIM is set up to run on the LSE clock (32768 Hz) (with a prescaler of 16, so the LPTIM is running at 2048 Hz)

To start a delay there is this HAL function :

HAL_LPTIM_TimeOut_Start_IT(&lptim1, uint32_t Period, uint32_t Timeout)

but why are there 2 parameters ?

If I set Timeout to (eg). 2048, I get the LPTIM interrupt one second later.

But what is Period doing ? What value should it be set in this simple case ?

If I set Period to (eg) 2048 as well, I observed that the first time, I get 2 interrupts, io 1...

Also I found that the timer after expiring, is restarted automatically, so I have to stop it. Would it be possible to start it as a one-shot timer, so it expires automatically ?

It all seemed like a simple application of LPTIM, but I could not find how to do it in the HAL docs not in the forums..

Thanks.

This topic has been closed for replies.

3 replies

Strooom
StrooomAuthor
Senior
April 12, 2023

I think I found a solution in the following way :

Using HAL_LPTIM_SetOnce_Start_IT() to start the timer. It still has two parameters, but I set the 'Period' to 0xFFFF and the 'Pulse' to the timeout time wanted.

Then this generates 2 interrupts : compareMatch and reload, but by adding only HAL_LPTIM_CompareMatchCallback() to handle the timer expire event, it works. The other interrupt (reload) is also firing but it calls an empty HAL_LPTIM_AutoReloadMatchCallback().

I think it could be disabled with some lower level calls, but the available HAL function enables both.

Amel NASRI
ST Technical Moderator
April 18, 2023

Hi @Strooom​ ,

To understand more how the LPTIM Timout works, I invite you to look to:

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
Strooom
StrooomAuthor
Senior
April 19, 2023

Hi Amel, thanks for your help. Actually I did consult those sources, but I did not find the answer there. Those examples are all focused on using the LPTIM to generate or handle hardware signals. My need was a pure software timer, so I can put the MCU into sleep for some time, and have it wake up after that. It's basically like a HAL_Delay() but then in (ultra) low power.