This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] CC2652R: How to use SysTick?

Part Number: CC2652R
Other Parts Discussed in Thread: CC2640R2F

SysTick can be used to achieve time tracking with 20.833 ns accuracy (i.e. same accuracy as the System Clock). 

More details, such as API description can be found here.

The code below can be used to replace the content of empty.c in the empty example.

This code does the following:

  • triggers an interrupt (to toggle the red LED of the launchpad) every 1 second
  • collect the systick value at pseudo random interval

/* Driver Header files */
#include <ti/drivers/GPIO.h>

/* RTOS header files */
#include <ti/sysbios/BIOS.h>

/* Driver configuration */
#include "ti_drivers_config.h"

/* For Systick */
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/systick.h)
#include DeviceFamily_constructPath(driverlib/interrupt.h)

 *  ======== mainThread ========
/* Systick callback executed every time the timer is wrapped */
void TickTimerISR(void){

const int NUM_TS_SAMPLES = 100;
uint32_t tickstamps[NUM_TS_SAMPLES] = {0};

void *mainThread(void *arg0)
     int i;

     /* GPIO initialization and configuration */

     /* Systick  configuration */
     SysTickPeriodSet(48000000); // 1s interrupt timing ==> TickTimerISR() is executed every 1 second

     while(1) {

         /* Random delay */
         volatile int delay = (123456 + 7890123*tickstamps[i]) % 1234567;

         /* Systick collection */
         tickstamps[i++] = SysTickValueGet();

         if(i == NUM_TS_SAMPLES)
             i = 0;

Note: The code provided here is applicable to pretty much all the CC26xx and CC13xx devices (including CC2640R2F, CC2651, CC2652R7, CC1311, etc.)