Skip to main content
Associate
Nov 2, 2026 11:51 AM UTC
Question

STM32L476 – LPTIM2 asynchronous external pulse counting in STOP2 mode

I am working on an equipment  based on an STM32L476 and would like to clarify the actual behaviour of LPTIM2 in STOP2 mode.

The objective is to count external pulses while the MCU is in STOP2, in order to minimise power consumption.

Hardware and configuration

  • MCU: STM32L476VET6
  • External pulse signal connected to PD12 (LPTIM2_IN1, AF14).
  • Pulse frequency: approximately 1 Hz.
  • Pulse signal: 0–3 V.
  • LPTIM2 configured as an external counter, with the following settings:
    • Clock source: LPTIM_CLOCKSOURCE_ULPTIM
    • Prescaler: DIV1
    • Counter source: LPTIM_COUNTERSOURCE_EXTERNAL
    • Input 1 source: GPIO
    • Input 2 source: GPIO
    • Rising edge polarity (CKPOL = 00)
    • No input filtering (CKFLT = 00).

Initialisation issue

When using the asynchronous clock configuration, the HAL function HAL_LPTIM_Counter_Start_IT() times out while waiting for the ARR register update to be acknowledged (ARROK).

This appears to be because the ARR update is synchronised with the external clock on LPTIM2_IN1. With a 1 Hz input signal, the update may take several seconds.

To avoid this problem, I initially configure LPTIM2 using the internal kernel clock (synchronous mode), load ARR successfully, and then switch to asynchronous mode by setting CKSEL = 1, disabling and re-enabling the peripheral.

This works correctly: LPTIM2 counts external pulses in normal operating mode.

STOP2 experiment

I then tested the same configuration with STOP2 enabled.

The MCU is periodically woken up by an RTC interrupt every second. I verified that the STOP2 code path is executed and that the program resumes after each RTC wake-up.

The observed count is approximately the same in both cases:

  • STOP2 disabled: approximately 72 CPM after 1 min 20 s.
  • STOP2 enabled: approximately 72 CPM after 1 min 20 s.

The input pulse generator runs continuously at approximately 1 Hz.

This suggests that LPTIM2 may continue counting external pulses while the MCU is in STOP2.

However, I have not yet confirmed this with a direct measurement of the supply current or by comparing the LPTIM2 counter value immediately before entering STOP2 and immediately after waking up.

My questions

  1. Is LPTIM2 expected to continue counting external pulses in asynchronous mode (CKSEL = 1) during STOP2 on the STM32L476?
  2. Is this behaviour documented or supported, despite the reference manual stating that LPTIM2 must be disabled before entering STOP2?
  3. Could this be an undocumented hardware capability, or am I overlooking something in the power-management configuration?

I am aware that ST application note AN4865 demonstrates asynchronous external pulse counting during STOP2 using LPTIM1. My question specifically concerns LPTIM2.

Any clarification from ST would be appreciated.

2 replies

jiangfan
ST Employee
Nov 5, 2026 5:57 AM UTC

For the STM32L476, do not rely on LPTIM2 counting external pulses in STOP2. The reference-manual requirement to disable LPTIM2 before entering STOP2 means this is not a documented, supported operating mode for LPTIM2.

CKSEL = 1 selects an external clock source for the LPTIM counter. It does not by itself guarantee that LPTIM2 remains powered and operational in STOP2. An asynchronous clock can avoid dependence on the normal peripheral clock, but it cannot override the STOP2 restrictions on the peripheral.

This is distinct from LPTIM1, which AN4865 describes using for asynchronous external pulse counting in STOP mode. That example should not be assumed to apply to LPTIM2.

If you have observed LPTIM2 counting during STOP2, treat it as an undocumented observation rather than a supported capability; behavior could depend on device conditions or configuration and may not be reliable across devices or revisions. Check that the device is actually entering STOP2, then compare the counter against a known number of input pulses across repeated tests. Also check the STM32L476 errata for your device revision.

For a design that must count pulses in STOP2, use the documented LPTIM1 approach, or another counting method explicitly supported for that mode.

NOTE: reviewed answer with help of AI

Associate
Nov 5, 2026 12:31 PM UTC

Thank you for your response.

As I mentioned, I am fully aware of the documentation you cite, As I mentioned, I am fully aware of the documentation you cite, but you have answered my questions:

Is LPTIM2 expected to continue counting external pulses in asynchronous mode (CKSEL = 1) during STOP2 on the STM32L476?

and

Is this behavior documented or supported, even though the reference manual states that LPTIM2 must be disabled before entering STOP2?

Your response is: "treat it as an undocumented observation rather than a supported capability." OK.

Could this be an undocumented hardware capability, or am I overlooking something in the power-management configuration?

Your response is: "treat it as an undocumented observation." OK.

For your information, in my setup, LPTIM2 (using asynchronous capture in STOP2 mode) only works when debug mode is enabled:

  • HAL_DBGMCU_EnableDBGStopMode();
  • HAL_DBGMCU_EnableDBGSleepMode();
  • HAL_DBGMCU_EnableDBGStandbyMode();

In non-debug mode, it no longer works.

Topic closed for me.