Page 1 of 1

STM32 Timer Question

Posted: Thu Feb 04, 2016 8:59 am
by major4x
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)?

Re: STM32 Timer Question

Posted: Thu Feb 04, 2016 10:15 am
by Giovanni
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

Re: STM32 Timer Question

Posted: Thu Feb 04, 2016 10:02 pm
by Korken
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

Re: STM32 Timer Question

Posted: Thu Feb 04, 2016 10:07 pm
by Giovanni
See the 4 reasons above.

Giovanni

Re: STM32 Timer Question

Posted: Thu Feb 04, 2016 10:17 pm
by Korken
>> 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. :)

Re: STM32 Timer Question

Posted: Fri Feb 05, 2016 8:25 pm
by Giovanni
Probably you should try an implementation :)

Giovanni

Re: STM32 Timer Question

Posted: Mon Feb 08, 2016 10:06 pm
by Korken
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.