Last active
January 19, 2026 18:00
-
-
Save jefftenney/02b313fe649a14b4c75237f925872d72 to your computer and use it in GitHub Desktop.
No-Drift FreeRTOS tick/tickless for STM32 via LPTIM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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. |
Hi Jeff,
I am trying to start a software timer within an ISR handler, the workflow is as described below:
- Suppress the tick
- 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
Thank you for your program, but it seems not well if I use LPTIM instead of the SYSTICK.
Here is some of program. I copy the lptimTick with out any change.
FreeRTOSConfig_Defautl.h
Pre and Post code:
For the low power, I will suspend some threads after power-on about 2 minutes.
Then I use EXTI interrupt, if it catched the button pressed, it will resume key detect thread.
Then the periphThread will check the button and response to the user Shell during the next 3 minutes depend on the
osTimerStart(displaySleepTimerID, DISPLAY_HOLD_TIME); -> DISPLAY_HOLD_TIMEHere is the periphThread
Then if button pressed, it will resume the display thread, and after the timer is over time, it will suspend again/
But usually, it can not work well after I press the button, sometimes it will be normal, I can certain that if I use the SYSTICK it will be OK.
Could you give me some tips, thank you!