Welcome to MSPM0G3519 Development Board repository
2. System Delay
System Delay
System Delay1. Learning ObjectivesSysTick Timer PrincipleRole of Delay2. Hardware Setup3. Experiment Steps1. Open SYSCONFIG Configuration Tool2. SysTick Timer Configuration3. Write Program4. Compile4. Program Analysis5. Experimental Phenomena
1. Learning Objectives
Learn the basic use of MSPM0G3519 motherboard pins.
Understand the usage of the SysTick timer.
SysTick Timer Principle
The SysTick timer is a commonly used hardware timer used to generate fixed-cycle interrupts or trigger timing operations. Its basic working principle is to count through the main clock (MCLK) to achieve precise time intervals.
The SysTick timer is a standard timer built into the Cortex-M0 processor. As a 24-bit down counter, it has auto-reload capability and can mask system interrupts. All controllers based on the M0 core are equipped with a SysTick timer, which makes porting programs between different devices simpler. The SysTick timer is typically used in operating systems to provide necessary clock ticks for task scheduling, acting as a "heartbeat" to ensure the system executes tasks on time. Since all M0 core chips contain a SysTick timer, programs do not need to reconfigure the timer when porting, making it easier to port compared to regular timers.
In the system clock configuration, the RCU provides the external clock for the Cortex system timer (SysTick) through MCLK. By default, the MCLK frequency is 32MHz. You can control or read the timer status by setting the SysTick control and status register. For more information about the system clock, refer to the clock tree section in the user manual.
Clock Tree:

Default Clock Path in Project:

The SysTick timer works as follows: After setting the initial value and enabling, each system clock cycle decrements the counter by 1. When the counter reaches 0, SysTick automatically reloads the initial value and continues counting, while setting the internal COUNTFLAG flag to 1 and triggering an interrupt (provided interrupts are enabled).
Role of Delay
A delay function is a function used to introduce an artificial delay in a program. Its main role is to pause the program execution for a specified time period. Simply put, the role of a delay function is to wait - essentially to wait for a period of time before executing the next code.
Hardware Response Waiting: Many hardware devices need a certain time to complete operations or stabilize. For example, after sending an initialization command to a display screen, if display data is sent immediately, display abnormalities may occur. Delays allow hardware sufficient time to complete initialization and ensure proper operation.
Implementing Timed Tasks: Delays help implement operations at fixed time intervals. For example, an automatic door controlled by a microcontroller checks infrared sensors for obstacles every 5 seconds. If no obstacle is detected, the door stays closed; if detected, the door opens and stays open for 2 seconds, then automatically closes.
User Interaction Optimization: In user interaction scenarios, delays can achieve better experience. For example, when a button is pressed, a delay can implement "debounce" functionality to avoid multiple triggers caused by mechanical vibration. Additionally, in status indicator light switching, delays control the blinking frequency to make the light flicker smoother and easier to observe.
2. Hardware Setup
This course does not require additional hardware. You can directly use the onboard LED light on the MSPM0G3519 motherboard. The previous course used imprecise delay, and this course uses SysTick timer to achieve precise delay.
We have set up two LED user lights on the motherboard. Users can customize their functions. The following uses LED1 as an example.
MSPM0G3519 Main Control Diagram

LED Part Schematic

3. Experiment Steps
1. Open SYSCONFIG Configuration Tool
Create a new empty project empty in CCS.


Find and open the empty.syscfg file in the left workspace of CCS.

In SYSCONFIG, select MCU peripherals on the left, find the SYSTICK option and click to enter. Click ADD in SYSTICK to add the SysTick timer.

2. SysTick Timer Configuration
The SysTick timer uses MCLK for timing, and MCLK is 32MHz. This means the time for each count is 1/32,000,000 = 0.00000003125 seconds. Suppose we set the count value to 32000, then the time for counting 32000 values is: 32000 x 0.00000003125 = 0.001 seconds = 1ms. Therefore, if we want to set a 1ms SysTick timer, we set the SysTick timer's count value to 32000.

Parameter description:
Initialize Period: Initial timer period.
Period (ln McLk Cycles): Set the periodic count value. Here we set it to 32000.
Calculated Period: Time taken for counting. The software automatically calculates this value.
Enable SysTick Interrupt: Whether to enable SysTick timer interrupt.
Interrupt Priority: Select interrupt priority. Here the highest priority interrupt is selected.
Enable SysTick And start Counting: Whether to enable SysTick timer and start counting.
Save the configuration in the .syscfg file using the shortcut key Ctrl+S.
After saving, compile.

3. Write Program
After configuring the SysTick timer, we also need to manually write the SysTick timer interrupt service function. Because we enabled the SysTick timer interrupt, when the SysTick timer's count value decrements from the set initial value to 0, it triggers an interrupt, and after triggering, it automatically executes the interrupt service function. The interrupt service function name for each interrupt is usually fixed and cannot be modified arbitrarily; otherwise, you will not be able to correctly enter the interrupt service function. The interrupt service function name is SysTick_Handler
In the empty.c file, write the following code
x#include "ti_msp_dl_config.h"
volatile unsigned int delay_times = 0;
//Accurate ms delay with tick timervoid delay_ms(unsigned int ms){ delay_times = ms; while( delay_times != 0 );}
int main(void){
SYSCFG_DL_init();
while (1) { //LED pin outputs high level DL_GPIO_setPins(LED1_PORT, LED1_PIN_2_PIN); delay_ms(1000); //LED pin outputs low level DL_GPIO_clearPins(LED1_PORT, LED1_PIN_2_PIN); delay_ms(1000); }}
void SysTick_Handler(void){ if( delay_times != 0 ) { delay_times--; }}4. Compile

Compilation was successful. You can now download the program to the development board.
4. Program Analysis
empty.c

Define a global variable delay_times to record the remaining milliseconds for delay.
delay_ms(): Implements precise millisecond-level delay.
main(): After initializing the system, calls DL_GPIO_setPins to specify pins to output high/low level to control LED light on/off.
SysTick_Handler(): In the interrupt, decrements delay_times. If delay_times is non-zero, decrements it by 1 each interrupt. When it decrements to 0, the delay is complete, and the while loop in delay_ms() exits.
5. Experimental Phenomena
After the program is downloaded, you can see LED1 on the MSPM0 development board light up for 1 second and turn off for 1 second, repeatedly.