The SysTick timer is a 24-bit down counter built into the Cortex-M series of ARM processors. It provides microsecond timing capabilities and is commonly used for operating system ticks in RTOS applications. The SysTick timer runs on the processor clock and can generate periodic interrupts for timing events.
Overview of SysTick Timer
The SysTick timer module includes a 24-bit down counter that counts down from a reload value to zero. Once the counter reaches zero, it generates an interrupt and reloads the counter value again. This creates a periodic tick interrupt that can be used for task scheduling in a real-time operating system (RTOS).
In addition to the down counter, the SysTick timer module contains a clock source, interrupt generation logic, and control registers. The clock source can either be the processor clock or an external reference clock. The control registers allow software to configure the timer reload value, interrupt enables, and operating modes.
SysTick Timer Key Features
- 24-bit down counter
- Programmable reload value
- Processor clock or external clock source
- Configurable interrupt enables
- Accessible control registers
Using the SysTick Timer
The SysTick timer is commonly used for the following purposes in Cortex-M embedded applications:
RTOS Tick Generation
The SysTick interrupt provides a periodic tick that can be used for task scheduling and timekeeping in a real-time operating system. By configuring the reload value, the RTOS can set the desired tick frequency. The tick handler then calls the scheduler to switch tasks.
Create Execution Delays
By polling the SysTick counter in a loop, firmware can create execution delays or timeouts for operations. This provides microsecond timing without blocking other interrupts.
Benchmarking
The SysTick counter can measure elapsed time between events in the application. This allows benchmarking routines, execution profiling, and performance monitoring.
Periodic Data Acquisition
With the periodic tick interrupt, the SysTick timer provides accurate pacing for reading sensors or sampling data at fixed intervals in the milliseconds to microseconds range.
SysTick Timer Registers
The SysTick timer includes several registers that control its operation:
- SYST_CSR – Control and status register to start/stop counter, generate interrupt, select clock source.
- SYST_RVR – Reload value register sets tick interval.
- SYST_CVR – Current value register indicates current counter value.
- SYST_CALIB – Calibration value register for clock frequency.
These registers allow complete control over the timer behavior in software. They are accessed using the System Timer (SYST) addresses in the Cortex-M memory map.
SysTick Interrupt Handler
The SysTick timer includes an interrupt line to the Nested Vectored Interrupt Controller (NVIC). When the timer expires, it asserts the SysTick interrupt to the NVIC. This triggers execution of the SysTick interrupt handler.
The user application must implement a SysTick_Handler() ISR to respond to the periodic tick interrupts. This ISR would contain the RTOS tick handler or other routines to execute on each tick.
SysTick Timer Configuration
To configure the SysTick timer, the firmware typically performs the following steps:
- Enable SysTick module in SYST_CSR
- Select clock source (internal or external)
- Write the desired reload value to SYST_RVR
- Enable SysTick interrupt
- Start the SysTick counter
- Implement SysTick_Handler() ISR
This configures the timer period and attaches the handler to service the interrupts. Once enabled, the SysTick timer will begin generating tick interrupts at the configured rate.
Using SysTick Timer with RTOS
For real-time operating systems, the SysTick timer is commonly used to generate the RTOS tick interrupts. This tick drives task scheduling and provides time reference to the kernel. To integrate SysTick with an RTOS:
- Configure RTOS tick rate by setting SYST_RVR
- Implement SysTick_Handler() to call RTOS tick handler
- Start SysTick timer
- In tick ISR, call OS tick function to schedule tasks
- OS uses ticks for timeout management, delays, etc
This RTOS integration allows task switching, time management, resource sharing under the control of the kernel. The SysTick tick provides consistent pacing for the scheduler.
Advantages of SysTick Timer
Key advantages of using the SysTick timer in Cortex-M systems:
- Dedicated timing peripheral, avoids loading main CPU
- Microsecond to millisecond accuracy
- Fully configurable with software accessible registers
- Integrated interrupt generation
- Common feature across Cortex-M chips
By offloading timing tasks from the CPU to the SysTick module, it can improve timing accuracy and lower software overhead in embedded applications.
Conclusion
The SysTick timer provides essential timekeeping capabilities in Cortex-M processors. Its 24-bit down counter and periodic interrupts enable accurate task scheduling, benchmarking, delays, timeouts, and other key functions. Proper configuration allows the SysTick timer to serve as the heartbeat for RTOS task switching. With its wide availability across the Cortex-M family, the SysTick timer eases portability and guarantees microsecond timing in most ARM embedded designs.