2.8. System Timer (SysTick)

About the SysTick

The SCS also includes a system timer (SysTick) that can be used by an operating system to ease porting from another platform. The SysTick can be polled by software or can be configured to generate an interrupt. The SysTick interrupt has its own entry in the vector table and therefore can have its own handler.

The SysTick is configured through the four registers described in Table 5.

Table 5. SysTick Registers

SysTick Control and Status0xE000E010basic control of SysTick e.g. enable, clock source, interrupt or poll
SysTick Reload Value0xE000E014value to load Current Value register when 0 is reached
SysTick Current Value0xE000E018the current value of the count down.
SysTick Calibration Value0xE000E01Cmight contain the number of ticks to generate a 10ms interval and other information, depending on the implementation

Configuring SysTick

To configure the SysTick you need to load the SysTick Reload Value register with the interval required between SysTick events. The timer interrupt or COUNTFLAG bit (in the SysTick Control and Status register) is activated on the transition from 1 to 0, therefore it activates every n+1 clock ticks. If a period of 100 is required 99 should be written to the SysTick Reload Value register. The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.

If you want to use the SysTick to generate an event at a timed interval, for example 1ms, you can use the SysTick Calibration Value Register to scale your value for the Reload register. The SysTick Calibration Value Register is a read-only register that contains the number of pulses for a period of 10ms, in the TENMS field (bits 0 to 23). This register also has a SKEW bit (30) that is used to indicate that the calibration for 10ms in the TENMS section is not exactly 10ms due to small variations in clock frequency. Bit 31 is used to indicate if the reference clock is provided.

The Control and Status Register allows you to select between polling the timer by reading COUNTFLAG (bit 16), or by the SysTick generating an interrupt.

By default the SysTick is configured for polling mode. In this mode, user code must read COUNTFLAG to ascertain if the SysTick event had occurred. This is indicated by COUNTFLAG being set. Reading of the Control and Status register clears the COUNTFLAG bit. To configure the SysTick to generate an interrupt you must set TICKINT (bit 1 of the SysTick Control and Status register) HIGH. You will also need to enable the appropriate interrupt in the NVIC. You must set CLKSOURCE (bit 2) to 1 to select the core clock and zero select the external reference clock.

The Timer is enabled by setting bit 0 of the SysTick Status and Control register.

Copyright © 2007. All rights reserved.ARM DAI0179B