Step 5: Add Application Code to the Project

Last modified by Microchip on 2026/08/10 12:32

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.

Note: This code is used for both internal and external clock configurations. Add the code to your project, then proceed to Step 6: Build, Program, and Observe the Output.

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.

Code:
    SYSTICK_TimerCallbackSet(&timeout_handler, (uintptr_t) NULL);
   
    SYSTICK_TimerStart();

                        Code

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.

Information

Tip: Press the CTRL key and left-click on the SYS_Initialize function. The click will open the implementation for the SYS_Initialize function.

Add the timeout_handler callback function after the header file inclusions, and add the LED_Toggle() function inside the callback function.

Code:
void timeout_handler(uintptr_t context)
{
 LED_Toggle();
}

                Code

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.

Back to Top