SAM C21 SysTick Example Project

Last modified by Microchip on 2023/11/09 09:01

Objective

This page provides a simple SAM C21 System Timer (SysTick) GCC code example for the ATSAMC21J18A MCU. The project configures the SysTick module to produce interrupts every millisecond, using the default CPU clock frequency (4 MHz). The SysTick handler routine is used to count these interrupt events and toggle the onboard LED once every second.

The application is designed to work using the SAM C21 Xplained PRO Evaluation Kit (ATSAMC21-XPRO) which contains the ATSAMC21J18A Arm® Cortex®-M0+ MCU.

SAM C21 Xplained PRO Evaluation Kit

This application uses:

  • CPU Core SysTick Timer Module, clocked by the default CPU clock (4 MHz)
  • PA15 (User LED, LED0)

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.

Reference Materials

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

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

Back to Top

Connection Diagram

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

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

Connection Diagram

The virtual COM port in the EDBG requires the terminal software to set the Data Terminal Ready (DTR) signal to enable the UART pins connected to the ATSAMC21J18A. If the DTR signal is not enabled, the UART pins on the EDBG are kept in high-z (tristate) rendering the COM port unusable. The DTR signal is set automatically by some terminal software, but it may have to be manually enabled in your terminal.

VCC Selection Header

The SAM C21 Xplained Pro has a 3-pin header labeled VCC-SEL on the board. This header can be used to select between 3.3 V and 5.0 V as the supply voltage for the ATSAMC21J18A, peripherals, and extension headers by placing a jumper on the left (3.3 V) or right (5.0 V). Selecting 5.0 V supplies the kit directly from the USB or an external 5.0 V source. Selecting 3.3 V supplies the kit from an onboard regulator.

Select 3.3V as VCC by jumpering the left 2 pins on this header as shown here in the red box:
Board View: 3.3V selected

Back to Top

Procedure

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

Atmel Studio 7 Showing connected Kit

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 "3514".

Open the Solution

Select File > Open > Project/Solution…

Atmel Studio Screenshot:  Open Project

Navigate to the solution folder and select the systick-initialization.atsln solution file:

Atmel Studio Solution folder


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 (click) on the project in the Solution Explorer window, then select Project > Properties as shown:

Properties Selection

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

Tool Settings Selection

Save the tool setting by clicking the Save All button:

Save Tool Setting


Rebuild/Program the Target

Finally, click on the Start Without Debugging icon in Atmel Studio which information 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.

Start Without Debugging icon

If prompted, upgrade the EDBG firmware on the board:

upgrade the EDBG firmware

You need to click on Start Without Debugging again after an EDBG firmware upgrade in order to rebuild/program the target.

Back to Top

Results

Board View:  LED Toggling

LED0 toggles every second.

Back to Top

Conclusions

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

Back to Top