Step 4: Add Application Code to the Project
Last modified by Microchip on 2026/06/26 07:40
Add Application Code to the Project
Once the project is generated, open the main.c file and declare the following variables outside the main() function.
/* Global variables stored in SRAM */
volatile uint32_t sram_global = 0x1234;
const uint32_t flash_global = 0x5678;
volatile uint32_t sram_global = 0x1234;
const uint32_t flash_global = 0x5678;

Add the following code inside the main() function and outside the while loop.
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
This line enables the SysTick timer in an Arm®-based microcontroller. SysTick->CTRL accesses the control register of the SysTick peripheral. The |= (OR) operator sets only the ENABLE bit (SysTick_CTRL_ENABLE_Msk) to 1 while preserving all other configuration bits. This is a safe way to start the timer without affecting existing settings.
Add the following lines of code inside the while loop.
/* Increment SRAM variables */
sram_global++;
/* Toggle User LED (GPIO Peripheral) */
LED_Toggle();
/* --- BREAKPOINT HERE --- */
__asm("nop");
sram_global++;
/* Toggle User LED (GPIO Peripheral) */
LED_Toggle();
/* --- BREAKPOINT HERE --- */
__asm("nop");

- SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; enables the SysTick timer, demonstrating system control space.
- sram_global++; increments a variable stored in SRAM, showing normal memory access by the CPU.
- LED_Toggle(); changes the state of the GPIO‑connected LED, demonstrating peripheral control.
- __asm("nop"); is a no‑operation assembly instruction placed intentionally so a debugger breakpoint can pause program execution at this point.