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 MPLAB® 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. In the main(void) function, add the callback function SYSTICK_TimerCallbackSet(&timeout_handler, (uintptr_t)NULL); immediately after SYS_Initialize(NULL);. Then, add the SYSTICK_TimerStart(); function.
SYSTICK_TimerCallbackSet(&timeout_handler, (uintptr_t) NULL);
SYSTICK_TimerStart();

The SYSTICK_TimerCallbackSet(&timeout_handler, (uintptr_t)NULL); function registers timeout_handler as the callback function that is executed whenever a SysTick timer interrupt occurs. The SYSTICK_TimerStart(); function starts the SysTick timer.
Add the timeout_handler callback function after the header file inclusions, and add the LED_Toggle() function inside the callback function.
void timeout_handler(uintptr_t context)
{
LED_Toggle();
}

The timeout_handler() function is a user-defined callback that is automatically invoked each time the SysTick timer generates an interrupt. In this callback function, the LED state is toggled using the LED_Toggle() function.