cancel
Showing results for 
Search instead for 
Did you mean: 

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

Strooom
Associate III

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.

3 REPLIES 3
Strooom
Associate III

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 Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

Strooom
Associate III

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.