Module 3: Creating and Building a New Bare-Metal Project
Overview
In this lesson, you will be introduced to the core embedded development workflow in VS Code® by creating a new embedded C project from scratch. You will learn how to select the target device, toolchain, and hardware, then build and program the firmware onto the PIC32CM MC00 Curiosity Nano board. The activity reinforces how common MPLAB® X IDE tasks—such as project creation and building—are performed in the VS Code environment using tasks and commands rather than a monolithic IDE interface.
Learning Objectives
Understand and apply the core embedded development workflow.
- Creating a new embedded C project
- Selecting device, toolchain, and hardware
- Building the project
Activity
Build and flash a simple firmware project to the Curiosity Nano board.
Creating a New Project: Getting Started
Click on the Explorer icon
on the Activity bar.
When no project is open in VS Code, you will see buttons to Open Folder, Clone Repository or Create MPLAB Project. Click on Create MPLAB Project.

Other options to create an MPLAB X IDE project are:
- In the Command Palette (Ctrl + Shift + P), enter MPLAB: Create Project
- In the Command Palette (Ctrl + Shift + P), enter MPLAB: Welcome to open the Get Started with MPLAB walkthrough tab. Then under Welcome, click on Create or Import MPLAB Project and in the drop-down click on Create New Project.
Creating a New Project: Setting up the Project
Once the request for a new project is made, a Quick Pick UI (drop-down menus) will open over the search/command palette requesting information that will be used to create the new project. Information about the PIC32CM MC00 Curiosity Nano board will be used here.
Give the project a name.
Select a name that will identify the project, for example, "pic32cm-mc00-cnano-flash-led" instead of "Project1".
Select the project location.
Choose the default location for this example.
Choose a device.
For the PIC32CM MC00 Curiosity Nano board, the project device is the PIC32CM1216MC00032.
Select the project type.
Application is the most common and will be used in this example.
Select the compiler.
Choose the latest version of the MPLAB XC32 C/C++ Compiler.
The new project and related files will be displayed in the Explorer view.

Basic Bare-Metal Example Project
The following is a simple bare-metal project designed for the PIC32CM MC00 Curiosity Nano development board that can be used in this newly created project to either get started or verify the project setup. The code simply toggles the User LED (LED0) after a short delay.
#define LED0 PORT_PA23
#define DELAY_VAL 65536
//#pragma config BOOTCFG_WDTCFG_WEN = CLEAR
int delay = DELAY_VAL;
int main(){
// Configure PA23 as an output
PORT_REGS->GROUP[0].PORT_DIRSET = LED0;
// Toggle LED0 after delay variable reaches 0
while(1) {
while(--delay);
delay = 65536;
PORT_REGS->GROUP[0].PORT_OUTTGL = LED0;}
return 0;
}
Build the Project
Ensure that the PIC32CM MC00 Curiosity Nano board is connected to the PC via a USB cable. See Module 2 for details.
In the Command Palette (Ctrl + Shift + P), enter "MPLAB CMake: Build" or click the build hammer icon
. If you want details on the CMake Runner, in the Command Palette, enter "Preferences: Open Settings (UI)".
A Note on Configuration Bits
Configuration bits are a collection of specialized bits that can only be modified at program time. Configuration bits are read during reset and enable or disable hardware features in the microcontroller. The features controlled by the configuration bits include but are not limited to the clock source, Watchdog Timer, brown-out detection, and memory read protection. Configuration bits are not executable code. Essentially, they are fuses located in the program memory space.
Each Microchip device has its own set of configuration bits. Individual device data sheets contain the definition for each of the bits. For example, find configuration bit information in the Special Features section of most PIC® MCU data sheets.
The setting for each configuration bit can be determined by directives written in the application software. The syntax for the configuration bit settings is available from the compiler or associated library manual. For example, the MPLAB XC8 compiler manual contains information on setting configuration bits using #pragma, whereas the AVR®-LibC manual contains information on setting fuses (avr/fuse.h) and lockbits (avr/lock.h) using macros.
When developing in VS Code, please reference the appropriate compiler manual and the device data sheet for details on setting configuration bits for your specific device.