SysTick Initialization Code Example

 Objective

This page provides a simple SAM D21 System Timer (SysTick) GCC code example for the ATSAMD21J18A MCU. The project configures the SysTick module to produce interrupts every millisecond, using the default CPU clock frequency (1 MHz).

The SysTick handler routine is used to count these interrupt events and toggle the onboard LED once every second.

This code example uses a direct/indirect MCU register C-coding style (i.e., no software framework) and is built using the GCC compiler toolchain within the Atmel Studio 7 IDE.

 
SAM D21 System Timer (SysTick) Overview
Learn more >

 Materials

Hardware Tools

Tool About Purchase
ATSAMD21-XPRO-50px.png
SAM D21 Xplained Pro
Evaluation Kit

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
swtool-28px.png
Atmel® Studio
Integrated Development Environment

Exercise Files

File Download
Installation
Instructions
Windows Linux Mac OSX
Example Project

We recommend extracting the .zip file to your C:\ folder.

You should see the folder C:\MTT\32arm\samd21\code-examples-gcc\systick\systick-initialization containing the solution systick-initialization.atsln.

 Connection Diagram

SAM D21 Xplained Pro contains an Embedded Debugger (EDBG) that can be used to program and debug the ATSAMD21J18A using Serial Wire Debug (SWD) interface. The EDBG also includes a Virtual Com port interface over UART, a Data Gateway Interface over SPI and TWI, and it monitors four of the SAM D21 GPIOs. Atmel Studio 7 is used as a front-end for the EDBG.

The LED0 is driven by this application and is connected to port PB30 as shown:

xpro-diagram-systick-initialization.png

 Procedure

Attach the SAM D21 Xplained Pro board to your computer using a USB A-to-MicroB cable. Start Atmel Studio 7. If the board has been successfully enumerated, you should see the board image come up in Studio as shown:

samd21-xplained-pro-enum-success.png

The board is identified by the last four digits of its serial number (see the sticker on the bottom of the board). In this example, the last four digits are "1344".

1

Open the Solution

Select File>Open>Project/Solution…

as7-open-systick-solution.png
as7-open-systick-solution-detail.png

2

Configure the Debugger

Next, you need to configure the debugger in Atmel Studio to discover and connect to the target EDBG IC on your Xplained Pro board.

First, select Project>Properties as shown:

as7-config-debugger-1.png

Next, under the project's 'Tool' settings, select your EDBG target from the pull-down. Select 'SWD' as the interface as shown:

as7-config-debugger-2.png

Save the tool setting by clicking the Save All button as shown:

as7-config-debugger-systick-init-3.png

3

Rebuild/Program the Target

Finally, select the Start Without Debugging icon in Atmel Studio which (i) re-builds the HEX file from the project source code, (ii) downloads/programs the HEX file onto the target MCU, (iii) and releases the target MCU Reset pin, allowing the program to execute.

as7-start-without-debugging.png

If prompted, upgrade the EDBG firmware on the board:

as7-edbg-firmware-upgrade.png

You will need to select Start Without Debugging once again after a EDBG firmware upgrade in order to rebuild/program the target.

 Results

systick-initialization-example-results.png

LED0 toggles every second.

 Conclusions

This project has provided a simple example of how to set up and use the SysTick timer on SAM D21 MCU.

© 2018 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.