Step 5: Add Application Code to the Project
This example application is implemented on the PIC32CM LS00 Curiosity Nano board to study the behavior of different clock sources using the SysTick timer. An LED is toggled at a fixed interval, and the toggle behavior is monitored using the Data Analyzer. This setup allows you to observe and compare the system's behavior under different clock sources.
Add the following application code to the generated project for both the internal and external clock configurations.
Application Code for the Project
Open the main.c file in the non-secure project. Within the int main(void) function, add the function call SYSTICK_TimerStart(); immediately after SYS_Initialize(NULL);.
SYSTICK_TimerStart();

The SYSTICK_TimerStart(); function starts the SysTick timer, which is used to generate delays in the application. Using this delay, the LED is toggled at a fixed interval.
Add LED_Toggle(); and SYSTICK_DelayUs(100); sequentially inside the while(true) loop in the main.c file.
LED_Toggle();
SYSTICK_DelayUs(100);

The LED_Toggle() function changes the state of the LED: if the LED is currently ON, it turns OFF, and vice versa. The SYSTICK_DelayUs(100) function generates a 100-μs delay using the SysTick timer, ensuring a controlled interval between each LED toggle.