Modify, Build, and Debug the Project on MPLAB® for VS Code® Extensions

Last modified by Microchip on 2026/10/08 11:03

Purpose

This tutorial demonstrates how to open a project, modify, build, and debug an application for the SAM9X75 using the MPLAB® for VS Code® Extensions, while gaining hands‑on experience with source‑level debugging using OpenOCD.

Hardware Pre-Requisite

  • SAM9X75 Curiosity Hybrid evaluation board

               SAM9X75 Curiosity Hybrid

  • Two USB Type-C® cables
  • Power the board via a 5V adapter through J14 or J1
  • Jumper settings:
    • Close 1-2 pins of jumper13 for the 5V power selection via FTDI USB(J14)
    • Close 2-3 pins of jumper13 for the 5V power selection via USB-A (J1)
    • Close jumper J3 to enable VDDBU
Warning

Ensure all required software from the "OpenOCD Debugging Prerequisites (Bare Metal and MPLAB® Harmony)" page is installed before proceeding.

Modify, Build and Debug an Application on the Target

Clone test_sam9x75 hybrid_curiosity from GitHub®.

Open the MPLAB Harmony project from the class material by following the steps below:​

  • Open MPLAB in VS Code. Click Create or Import MPLAB Project and select Open MPLAB X Project Folder.
  • Navigate to your project folder cloned via git. Click Select Folder to import the project.

Open existing project

 


Open main.c file.

  • This main.c code waits for user input through the console.
  • Based on the entered value, it triggers different LED flashing patterns.
Information

Note: You can further modify the code to experiment with additional peripherals.

main.c code


To build the project, confirm the compiler details. To do this, go to the Command Palette and launch MPLAB: Edit project properties (UI). Go to Toolchain and confirm that XC32 is chosen.

Compiler settings


By default, MPLAB X IDE only generates ELF and HEX format output files. To generate application output in binary format, a post-build step needs to be added to the project properties.

To do this, go to Overview > Post-build Steps > Add Item. Then add the following command:

${MP_CC_DIR}/xc32-objcopy -O binary %{TargetDirRelative}/%{ConfigurationName}.elf %{TargetDirRelative}/harmony.bin

Add post-build step


Clean and build the project using MPLAB CMake: Clean and build. You will see a message on the output console that the project was successfully built. This completes the building of the MPLAB Harmony application.

CMake Build


Warning

To resolve 'unable to find header file' errors, if any, update your project configuration: View > Command Palette > MPLAB: Edit Project Properties (UI) > Compiler > Global > Include Directories > Add Path. (Your project configuration path).

Add Path

Warning

If the long path and toolchain unsupported error occurs, click Yes in the pop-up to enable long path support for the toolchain. Then rebuild the project.

Enable long path


Warning

This step is only necessary for using the Cortex-Debug extension with the on-board FTDI debugger. This is not necessary for using the MPLAB extensions with the MPLAB PICKit® 5 in-circuit debugger/programmer.

Note the OpenOCD configuration files in the project folder:

  1. sam9x75.cfg defines settings such as the interface, target device, transport, reset behavior, and JTAG/SWD parameters, which are essential for establishing the debug session.
    • Copy sam9x75.cfg file from the GitHub directory to the user project.
  2. launch.json specifies details such as the executable file, GDB path, OpenOCD server connection, configuration files, and debug actions like reset, halt, load, and run.
    •  Copy launch.json ​file from the GitHub folder to the user project/.vscode.

​Add required files to the project


Copy at91bootstrap.elf from GitHub into the ./binaries folder of the project directory. This at91bootstrap is used to debug an MPLAB Harmony application on VS Code.

Add at91bootstrap

Project properties are configured with the required settings to ensure a successful and error-free build of the application.


Now ensure 1-2 pins of the jumper J13 are closed to power the board via FTDI USB. Open jumpers J10 and J9 to disable boot from QSPI and NAND.

Power the board by connecting a USB Type-C cable to J14 from the host PC. Now press the reset button.

hardware setup


Now execute UsbDriverTool.exe from Designing_with_Hybrid_MCU_pre_work\Tools\UsbDriverTool.

Configure Channel A of the FT4232H to use the libusb-winusb driver so it can be used for OpenOCD-based debugging in VS Code. The goal is to switch FT4232H/FT4232HQ Channel A to the WinUSB (libusb-winusb) driver. This is required because OpenOCD uses libusb/WinUSB to talk to the JTAG interface, and it will not work if Channel A is still using the default FTDI driver.

Configure Channel A as JTAG

 


Connect to Channel C of the FT4232H to use the FTDI using the extension Serial Monitor in VS Code.

  • Serial monitor configuration and connection: 
    • The image shows the VS Code Serial Monitor with the correct settings selected, including Serial monitor mode, COM25 – USB Serial Port (from the on‑board FT4232HQ), Line Ending as CR and a baud rate of 115200, with monitoring actively running.
  • Sending commands to the target: 
    • At the bottom, you can send inputs as text, indicating that control commands are being transmitted from the host to the target over UART, enabling interactive control of application behavior in real time.
  • You can see the “RomBOOT” message being printed on the console upon reset every 15 seconds.​​​​​​
Information

For SAM9X75 Curiosity Hybrid, Channel C of the FT4232H is connected to UART.

Find the Channel C COM port number from Device Manager as follows:

Channel C

RomBoot


Now start to debug. Go to View > Command Palette > Debug: Start Debugging. When prompted choose Cortex debug/OpenOCD debug or click the debug symbol as shown in the accompanying image:

Debugging


Click the run or play button in the debugging window and observe output logs in the serial console.
Selecting different pattern numbers in the serial console causes the LEDs to flash in different patterns.

The sample output is shown:

Debug Output

This image shows the VS Code Serial Monitor output where the system is waiting for user input to select an LED pattern.

The serial console waits for input, and when the user presses ‘0’, it flashes a specific LED pattern 10 times with a 250ms interval and then returns to waiting for the next user input.

Output

Back to Top

Results

You successfully modified and built an application for the SAM9X75 using the MPLAB for VS Code Extensions. You verified correct functionality through source‑level debugging with OpenOCD, observing application behavior via the serial console.

Back to Top

Collaterals

Back to Top