Skip to content

SysTick

Glenn Lopez edited this page Feb 5, 2017 · 13 revisions

SysTick Address Definitions

The code snippet below are address definitions used for the SysTick timer examples in this guide. Visit the STCTRL section of the TM4C123G datasheet for more info on the registers used for the SysTick timer. > SysTick is a timer feature that is available in all Cortex-M microcontrollers

#define NVIC_ST_CTRL_R          (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_RELOAD_R        (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R       (*((volatile unsigned long *)0xE000E018))
#define NVIC_ST_CTRL_COUNT      0x00010000  // Count flag
#define NVIC_ST_CTRL_CLK_SRC    0x00000004  // Clock Source
#define NVIC_ST_CTRL_INTEN      0x00000002  // Interrupt enable
#define NVIC_ST_CTRL_ENABLE     0x00000001  // Counter mode
#define NVIC_ST_RELOAD_M        0x00FFFFFF  // Counter load value
Video: https://youtu.be/fMqCBMWZ0pk

SysTick Initialization

void SysTick_Init(void){
  NVIC_ST_CTRL_R = 0;           
  NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M; 
  NVIC_ST_CURRENT_R = 0;                                            
  NVIC_ST_CTRL_R = NVIC_ST_CTRL_ENABLE+NVIC_ST_CTRL_CLK_SRC;
}

SysTick Busy-Wait function

void SysTick_Wait(unsigned long delay){
  volatile unsigned long elapsedTime;
  unsigned long startTime = NVIC_ST_CURRENT_R;
  do{
    elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF;
  }
  while(elapsedTime <= delay);
}

PLL System Clock Calculation

  1. Calculate how long it takes (in seconds) for one clock tick to decrement
    • 1 tick = (1/System Clock) * 10^9 nano seconds
      • example: (1/80MHz) * 10^9 = 12.5 nano seconds

TM4C123G (datasheet)

TM4C123G is a 32bit MCU based on the ARM® Cortex®-M4F architecture. Make sure to read C++ Support on TI Compilers if you plan on using C++

Clone this wiki locally