On ARM architecture, a special peripheral that I appreciated much is this: a dedicated timer called system tick, which use as system tick for RTOS or task scheduler.
The register settings is much simpler as it is meant to be used as system tick in software. In this tutorial, again, we will be using this timer to
toggle the LED. On second thought, lets have some fun instead, lets build a Operating System! Unfortunately, this operating system is only have a round-robin task scheduler.
I shall split this into 2 session, first is a guide to enabling the System Tick. The second tutorial will be putting System Tick into our task scheduler.
Do take note that the system tick description is in the programming manual. In here, I will be setting the system tick to timeout every 100ms. This is too big for normal application, but since I will be running tasks with 1seconds and 2 seconds timeout later on, it is good enough here.
After running so many tutorial, finally I saw some easy guide as below:
|
Guide On Setting Up SysTick |
First is the program reload value. With system clock running at 48MHz, each clock running at 1/48MHz, which is 20.83nS. To get to 100ms, I will need 4800000 tick. This correspond to the reload value that I should use.
|
SysTick Reload Value:
STK_RVR : 4800000 |
Next I just need to clear the current value to zero
|
Clear SysTick Current Count
STK_CVR : 0 |
And finally configure program control and status register
|
Setting Control and Status Register
STK_CSR : 0x000007 |
That's it. A few SFR setting and we are good to go. Just go to
github(Lesson5_SysTick_Blinking_LED) to grab the source code. And it seems that I still need the blinking LED in this and next (task scheduler) example. Below is the code snippet on SFR settings.
|
Source Code To Setup SysTick |
No comments:
Post a Comment