Getting Started With MPLAB® Harmony v3 Peripheral Libraries on PIC32CM JH (Arm® Cortex®-M0+) MCUs

Last modified by Microchip on 2025/10/02 16:26

Objective

This tutorial demonstrates how to develop a simple LED control application using the PIC32CM JH Value Line Curiosity Nano + Touch Evaluation Kit and the MPLAB® Harmony v3 software framework. The application toggles an LED at regular intervals and prints the current toggle rate to a serial terminal. Each time the onboard user switch is pressed, the toggle rate cycles through 500 milliseconds (ms), 1 second (s), 2s, 4s, and then back to 500 ms. The project utilizes various peripheral modules including the External Interrupt Controller (EIC) to detect switch presses, the Real-Time Counter (RTC) to generate periodic timeouts, PORT for LED control, Direct Memory Access Controller (DMAC) for efficient serial communication, and SERCOM (USART) for transmitting messages to the terminal. This application provides a hands-on introduction to using MPLAB Harmony v3 for configuring and integrating peripherals on the PIC32CM JH microcontroller.

The application you create will utilize:

  • PORT PLIB to toggle the onboard LED connected to a PORT pin
  • RTC PLIB to generate periodic timeouts for LED toggling
  • EIC PLIB to detect user switch press and cycle the LED toggle rate
  • SERCOM (configured as USART) PLIB to print the current LED toggle rate to a serial terminal
  • DMAC PLIB to transfer USART data efficiently without CPU involvement

In the process, this application also demonstrates the use of callback functions for handling switch interrupts and timer events.

Two Ways to Use This Tutorial

  1. Create the project from scratch:
    • Use the provided source files and step-by-step instructions.
  2. Use the solution project as an example:
    • Build the solution project and program it to the PIC32CM JH-Value Line Curiosity Nano + Touch Evaluation Kit to observe the expected behavior.

Lab Objectives

  1. Create an MPLAB Harmony v3 project for the PIC32CM JH Value Line Curiosity Nano + Touch Evaluation Kit from scratch using MPLAB X IDE.
  2. Use MPLAB Code Configurator (MCC) to configure and generate Harmony v3 PLIBs code for the following peripherals:
    • RTC to generate periodic timeouts for LED toggling
    • EIC to handle user switch interrupts
    • PORT to control the onboard LED
    • SERCOM (USART) to send data to a serial terminal
    • DMAC to perform USART data transfers without CPU intervention
  3. Use Harmony v3 Peripheral Library (PLIB) Application Programming Interfaces (APIs) to implement periodic LED toggling with rate change on switch press and display the current toggle rate on a serial terminal.
  4. Demonstrate the use of interrupt-driven callbacks to handle RTC and switch events in real time.

Back to Top

Reference Materials

Apart from the hardware tools listed above, the following items are required:

  • USB Type-A male to Type-C male cable for programming and debugging
Information

Note: The PIC32CM JH-Value Line Curiosity Nano + Touch Evaluation Kit features an on-board nano debugger (nEDBG) that enables programming, debugging, and serial communication via a USB Type-C connection—no external tools needed. It includes a user LED, switch, capacitive touch button, and supports adjustable target voltage from 1.7V to 3.6V.

Information

Note: This project has been verified to work with the following versions of software tools:

Because we regularly update our tools, occasionally you may discover an issue while using the newer versions. If you suspect that to be the case, we recommend that you double-check and use the same versions that the project was tested with.

You will use the MPLAB X IDE MCC Content Manager for MPLAB Harmony Projects to download the following repositories from GitHub:

  • CSP: The following table shows the summary of contents.
FolderDescription
appsExample applications for Chip Support Package (CSP) library components
archInitialization and starter code templates and data
docsCSP library help documentation
peripheralPLIB templates and configuration data

Connection Diagram

Connect the PIC32CM JH VL Curiosity Nano + Touch Evaluation Kit to the host PC using a Type-A male to Type-C USB cable. Plug the Type-C end into the board’s Debug USB port (J103), and the Type-A end into a USB port on your PC. This connection enables power supply, programming, debugging, and serial communication through the on-board nano debugger (nEDBG).

Connection Diagram

Back to Top

Overview

This lab shows you how to create an MPLAB Harmony v3 project from scratch, to configure and generate:

  • MPLAB Harmony v3 Peripheral Libraries code for the RTC peripheral
  • MPLAB Harmony v3 Peripheral Libraries code for the EIC and PORTS peripherals
  • MPLAB Harmony v3 Peripheral Libraries code for the Universal Synchronous/Asynchronous Receiver/Transmitter (USART), and DMA peripherals
Information

Note: This video provides an overview to get started with the application discussed in this lab.

 

Application

The application toggles an on-board user LED at a periodic rate and prints the current LED toggle interval to the serial terminal over a virtual COM port. The default toggle interval is 500 ms, and this period is cyclically updated to 1s, 2s, 4s, and back to 500 ms whenever the user presses switch SW200 on the PIC32CM JH VL Curiosity Nano + Touch Evaluation Kit.

The application uses MPLAB Harmony v3 Peripheral Libraries (PLIBs) configured through MCC. During system initialization, the application sets up clock, PORT, and required peripherals through a call to the SYS_Initialize function. It also registers callback event handlers for RTC, EIC, and SERCOM (USART) peripherals. These callback handlers are automatically invoked by their respective PLIBs when the corresponding events (like timeout expiration or switch press) occur.

Secure Application Flow Sequence

Information

Note:

  1. A callback event handler for EIC is triggered when the user presses SW200, allowing the application to update the LED toggle rate.
  2. RTC peripheral is used for implementing the time period instead of the timer peripheral. This demonstrates how to configure and use RTC peripherals in an application (particularly low-power applications).
  3. Callback event handlers for SERCOM1 (configured as USART) are not registered as the actual USART data transfer, and it is accomplished by the DMA. The DMA calls back the callback event handlers when the DMA transfer requests are complete.

The application continuously monitors the RTC interrupt to determine when the next LED toggle event should occur. On each timeout, the user LED is toggled, and a message indicating the current interval (e.g., "Toggling LED every 100 ms") is formatted and sent to the serial terminal using the SERCOM USART with DMAC. The RTC continues to generate interrupts based on the currently selected interval.

When SW200 is pressed, the EIC interrupt triggers a callback that updates the RTC timeout interval. The toggle rate changes in the sequence: 500 ms → 1 s → 2 s → 4 s → 500 ms, and this cycle repeats with each switch press. Each new rate is reflected in the serial output, giving the user real-time feedback on the system’s behavior.

This demo effectively demonstrates how to:

  • Use RTC as a periodic interrupt source
  • Handle switch input with EIC and callback functions
  • Control I/O using PORT
  • Communicate over USART with DMAC
  • Design a simple event-driven embedded application using MPLAB Harmony v3 on a PIC32CM JH microcontroller

LED Running Sequence

Lab Source Files and Solutions

Download the project file.

This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the lab as per the following step-by-step instructions (see the "Procedure" section on this page).

​The contents of this ZIP file need to be placed in a folder of your choice.

  1. The project location of an MPLAB Harmony v3 project is independent of the location of the MPLAB Harmony Framework path (i.e., you don't need to create or place an MPLAB Harmony v3 project in a relative path under the MPLAB Harmony v3 framework folder).

Note:

  • Windows® OS has a maximum path length of 260 characters and a command-line limitation for Windows OS of 8191 characters.
  • The Arm® TrustZone® technology-based project comes with a long path name, hence the project build may fail due to exceeding Window's maximum path length.
  • Workaround: Move the project folder to the C:/ drive to reduce the project path length then open in MPLAB X IDE to build the project.

     2. The point above is true because when created, a Harmony v3 project generates all the referred source and header files and libraries (if any) under the project folder.

Extracting the ZIP file creates the following folders:

  • pic32cm_jh_vl_getting_started contains the lab solution and source files (in the dev_files folder).
    • The project folder contains the completed lab solution project which consists of firmware. It can be directly built and programmed on the hardware to observe expected behavior.

Back to Top

Procedure

​Note: All steps must be completed before you can build, download, and run the application.

Lab Index

Step 1: Create a Getting Started Project on PIC32CM JH-VL Curiosity Nano Kit

  • Step 1.1 - Create an MPLAB® Harmony v3 Application Project using MPLAB® X IDE
  • Step 1.2 - Verify Clock Settings

Step 2: Configure DMA, USART, and RTC Peripheral Libraries

  • Step 2.1 - Configure RTC Peripheral Library
  • Step 2.2 - Configure USART Peripheral Library and USART Pins
  • Step 2.3 - Configure DMA Peripheral Library

Step 3: Configure Pins for Switch and LED

  • Step 3.1 - Configure Switch Button Pin with EIC to Generate an Interrupt
  • Step 3.2 - Configure the LED Pin 

Step 4: Generate the Code
Step 5: Add Application Code to the Project
Step 6: Build, Program, and Observe the Outputs

Back to Top