Skip to content

Instantly share code, notes, and snippets.

@jefftenney
Last active January 19, 2026 18:00
Show Gist options
  • Select an option

  • Save jefftenney/02b313fe649a14b4c75237f925872d72 to your computer and use it in GitHub Desktop.

Select an option

Save jefftenney/02b313fe649a14b4c75237f925872d72 to your computer and use it in GitHub Desktop.
No-Drift FreeRTOS tick/tickless for STM32 via LPTIM
// The original github gist for lptimTick.c is no longer maintained. It grew into a
// full-fledged repository, https://github.com/jefftenney/LPTIM-Tick/, which integrates
// lptimTick.c into a project for the STM32L476.
//
// Another repo, https://github.com/jefftenney/LPTIM-Tick-U5/, integrates a newer
// version of lptimTick.c into a project for STM32U585. The newer version of
// lptimTick.c supports the newest revision of the LPTIM timer silicon.
//
// Thus there are two actively maintained versions of lptimTick.c, and you must choose
// the correct one for your LPTIM silicon:
//
// Type 1 or 2: https://github.com/jefftenney/LPTIM-Tick/blob/main/Core/Src/lptimTick.c
// Type 3: https://github.com/jefftenney/LPTIM-Tick-U5/blob/main/Core/Src/lptimTick.c
//
// To determine which LPTIM variant is in your STM32, see AN4865 from ST.
//
// This gist is not actively maintained, but it still contains all original revisions
// of lptimTick.c and github comments for historical value.
@BaselHn
Copy link

BaselHn commented Jun 30, 2025

Hi Jeff,

I am trying to start a software timer within an ISR handler, the workflow is as described below:

  1. Suppress the tick
  2. Enter sleep mode, waiting for an interrupt, and then use WFI.
    Then I wake up the MCU by an external interrupt, for example, a push button
    The MCU wakes up and enables the interrupts, then the ISR starts to run and tries to start the software timer from the ISR.
    What happens is that the software timer fires immediately, which I suspect that the timer fires because the tick is not yet restored and the OS tick is not stable.
    How can I solve this Issue?

Note: I am using STM32H562 MCU with tickless idle, and LPtimer following your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment