STM32 Timer Question
Moderator: RoccoMarco
STM32 Timer Question
I have a general question: why the STM32 uses the SysTick timer in periodic mode and the TIM2 timer in free-running mode (as opposed to using SysTick in both periodic and free-running)?
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Timer Question
Hi,
Several reasons:
1) Systick is 24 bits, tickless requires a 16 or 32 bytes counter.
2) It is a down-counter.
3) Not able of free running.
4) It does not have a comparator.
It is meant for periodic interrupts and it does just that.
Giovanni
Several reasons:
1) Systick is 24 bits, tickless requires a 16 or 32 bytes counter.
2) It is a down-counter.
3) Not able of free running.
4) It does not have a comparator.
It is meant for periodic interrupts and it does just that.
Giovanni
Re: STM32 Timer Question
That is not quite true, we use the SysTick as a normal timer in the RTFM-kernel (http://www.rtfm-lang.org/ - I know bad name...).
You just calculate the time to the next scheduled event and set SysTick to this and then lets it downcount, while at the interrupt we handle it just like any normal timer.
It is a good timer to use for any generic timing use, and I cannot see the reason for not using it in tickless mode.
You can read here about the correctness of using this here where we discuss how the SysTick can be used with the DWT counter (a paper I helped a little in):
http://pure.ltu.se/portal/en/publicatio ... ca%29.html
You just calculate the time to the next scheduled event and set SysTick to this and then lets it downcount, while at the interrupt we handle it just like any normal timer.
It is a good timer to use for any generic timing use, and I cannot see the reason for not using it in tickless mode.
You can read here about the correctness of using this here where we discuss how the SysTick can be used with the DWT counter (a paper I helped a little in):
http://pure.ltu.se/portal/en/publicatio ... ca%29.html
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Timer Question
>> See the 4 reasons above.
1) Systick is 24 bits, tickless requires a 16 or 32 bytes counter.
Design choice to not implement 24-bit support, just use the SysTick as a 16-bit timer.
2) It is a down-counter.
Irrelevant, a downcounter is just a "startvalue - upcounter".
3) Not able of free running.
If the true time passed is relevant, use the DWT counter in conjunction with the SysTick (as described in our paper, where timing accuracy is the main goal).
4) It does not have a comparator.
It does, at 0.
I can understand that there might be some work to support this, but to only use the SysTick/DWT is a major advantage when it comes to compatibility with other Cortex families.
But, this are just suggestions for future ideas and generalizations.
1) Systick is 24 bits, tickless requires a 16 or 32 bytes counter.
Design choice to not implement 24-bit support, just use the SysTick as a 16-bit timer.
2) It is a down-counter.
Irrelevant, a downcounter is just a "startvalue - upcounter".
3) Not able of free running.
If the true time passed is relevant, use the DWT counter in conjunction with the SysTick (as described in our paper, where timing accuracy is the main goal).
4) It does not have a comparator.
It does, at 0.
I can understand that there might be some work to support this, but to only use the SysTick/DWT is a major advantage when it comes to compatibility with other Cortex families.
But, this are just suggestions for future ideas and generalizations.
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Timer Question
I was hoping to inspire you 
I helped one of my professors with this in the RTFM-kernel, but it was interesting.
Then again, development time comes in and so on.
Might have a look at it in the future when I know the "core" of Chibi a little better.
I helped one of my professors with this in the RTFM-kernel, but it was interesting.
Then again, development time comes in and so on.
Might have a look at it in the future when I know the "core" of Chibi a little better.