Skip to main content
Associate III
January 14, 2025
Solved

How to run a clock while device is asleep?

  • January 14, 2025
  • 2 replies
  • 1304 views

Hello,

My goal is to setup a timer which also runs when the device is in (Zigbee) sleep mode. I have tried to adapt HAL_GetTick() to be run by LPTIM1 on an STM32WB5MMG, which led to the device not boot anymore. I also tried setup timestamps on the RTC which did not solve the original problem.

Is there some predefined solution to solve my problem or some example projects that demonstrate the use of LPTIM1 for my usecase?

Best regards

Best answer by Lubos KOUDELKA

Hello,
Zigbee example provided in our repositories are using Timer server(AN5289 - chapter 4.5 Timer Server for more info), which is clocked by RTC-LSE (running also in low power modes down to shutdown).

Would Timer server functionality fulfil your needs?

Best regards,
Lubos

2 replies

Lubos KOUDELKA
Lubos KOUDELKABest answer
ST Employee
January 23, 2025

Hello,
Zigbee example provided in our repositories are using Timer server(AN5289 - chapter 4.5 Timer Server for more info), which is clocked by RTC-LSE (running also in low power modes down to shutdown).

Would Timer server functionality fulfil your needs?

Best regards,
Lubos

NameAuthor
Associate III
January 27, 2025

 Hello,

I am trying to implement timestamps/ticks for sd-card logging and HW_TS seems not be ideal for this task, because I have to setup a new timer which makes the device wakeup frequently in order to increase a variable. I think about using

uint16_t HW_TS_RTC_ReadLeftTicksToCount(void); //Returns the number of ticks to count before the next
interrupt.

but from my understanding it reports only the ticks left to any interrupt from any timer setup in the project.
Is there a way to read ticks without the need to setup a new HW_TS?

Best regards

Associate II
January 23, 2025

Hi,

I'm not yet familiar with all the peripheralS of STM32 MCU, but in any case it's possible add an external oscillator to microcontroller design. Depending frequency, accuracy, stability; it can be a crystal, ceramic, or RC. Some circuits can be made with CMOS inverters, oscillators divisors, or if there is relationship with HMS, dedicated IC at low frequency.

As inverter: 74HC04. CD2040, CD2040,CD2060 and their evolutions with HC series as oscillators and divisors. DS3231 as Real Time Clock, or equivalent.  An famous NE 555 can do the job until 1Mhz. The last question is sleep mode. External oscillator can be consuming, Then the right balance must be found to deal with the sleep current.

Regards.

Butterfly