Module 5: Programming and Debugging in VS Code®

Last modified by Microchip on 2026/10/12 13:10

Overview

In this lesson, you will learn how to execute common debugging tasks to build confidence in using the VS Code® debugger with MPLAB® Extensions. You will learn how to start and stop debug sessions, set and clear breakpoints, step through code, and inspect CPU registers, variables, and memory. The hands‑on activity emphasizes observing live system behavior on real hardware, demonstrating that VS Code provides the same core debugging capabilities as MPLAB X IDE, even though the workflow and interface are different.

Learning Objectives

Build confidence with day‑to‑day debugging tasks:

  • Starting and stopping a debug session
  • Setting and clearing breakpoints
  • Stepping through code
  • Viewing CPU registers, watches, and memory

Activity

Debug a running application and observe live system state.

Decide If a Launch File is Needed

For simple applications or debugging scenarios, you can run and debug a program without creating a launch file for specific debugging configurations. VS Code will try to run your currently active file when you click on the F5 key or select menu item Run > Start Debugging or select Start Debugging under the Hammer icon drop-down. However, for most debugging scenarios you need to create a launch file (launch.json) to store debugging configuration information.

For the bare-metal project, no launch file is needed. Select a method to start debugging. Then jump to Step 7.

For the MPLAB Code Configurator (MCC) Harmony project, a launch file will be created. This process is described in the next section.

Create a Launch File

Click the Run and Debug icon Run And Debug on the activity bar.

The Run and Debug button will then appear in the Primary Side Bar.

Run and Debug button


Click on the create a launch.json file link under the Run and Debug button. You may be asked to:

  • Select the workspace: Choose pic32cm-mc00-cnano-flash-led
  • Select the debugger: Choose MPLAB Debugger
  • Select the target: Choose the PIC32CM MC00 Curiosity Nano board

A launch file (launch.json) will be created in the .vscode folder.

Launch File Added


When the contents of the launch file are first displayed, a selection window to set up additional launch configurations will appear. Click outside of this window to close it.

Launch File Browser Selections


The launch file contents are now visible. As stated in the comments, mouse over any attribute to read its description. If you do not want code execution to automatically stop after launch, set the stopOnEntry attribute to false.

Launch File Basic

For more information, go to "Launch configurations" in VS Code documentation.

This video has been shortened to cover creating a launch configuration file for the MCC Harmony project example.

Program, Run and Debug

Ensure you are in the Run and Debug Run and Debug section.

Then click Start-Debugging-Icon-Dark.png to start debugging.

Start Debugging


The board will be programmed with an ELF file for debugging. The code will then run. On the board, the User LED will be blinking quickly. If you have a new board that contained firmware for a blinking LED, you will notice that the LED is now blinking at a faster rate.

Program Run


Near the top center of the VS Code interface, you will find a debug toolbar.

Debug Toolbar

The controls, from left to right, are:

  • Pause/Continue
  • Step Over
  • Step Into
  • Step Out
  • Restart
  • Stop/Terminate

Pause execution and then Step Out of the while(true) loop.

This video covers the Program, Run, and Debug section, and starts with connecting the tool and setting breakpoints within main.c, followed by starting a debug session using the configuration created previously, for the MCC code example used previously. 

Back to Top

Dev Tool Bits | Start Building & Debugging With MPLAB® Tools for VS Code®

This video has been cropped to discuss the debugging portion. To see the portion on building, go to Module 4.

Back to Top

Debugging and Viewing Window Content

This video is part of a series. The content presented here is as follows:

  • Begin with a review of creating a launch configuration. After launch, start and stop a debug session using debug bar buttons or breakpoints. On stop, work with stepping through code.
  • Next, find windows that display information on local variables, CPU registers, the call stack, watches, and device memory. Then watch how they change during debug run and halt.

Back to Top