Getting Started With MPLAB® Harmony v3 Peripheral Libraries on PIC32CM GV-VL (Arm® Cortex®-M0+) MCUs
Objective
This tutorial shows you how to create a basic peripheral library application on a PIC32CM GV-Value Line Curiosity Nano+ Touch microcontroller (MCU) using MPLAB® Harmony v3 software framework.
MPLAB Harmony v3 is a flexible, fully-integrated, embedded software development framework for 32-bit microcontrollers (MCUs) and microprocessors (MPUs). MPLAB Harmony v3 includes the MPLAB Code Configurator (MCC) tool, a set of modular Peripheral Libraries (PLIBs), drivers, system services, middleware, and numerous example applications, all of which are designed to help you quickly and easily develop powerful and efficient embedded software for Microchip’s 32-bit PIC® and SAM devices.
This tutorial demonstrates how to utilize MCC to create an application that provides a foundation for developing applications on PIC32CM GV-VL MCUs using the MPLAB Harmony v3 software framework.
The application makes use of the PIC32CM GV-Value Line Curiosity Nano+ Touch Evaluation Kit.
The application showcases an LED that toggles based on a timeout and prints the LED toggling rate on a serial terminal. The periodicity of the timeout will change from 500 milliseconds (ms) to 1 second (s), 2s, 4s and back to 500 ms each time the mechanical switch on the PIC32CM GV VL Curiosity Nano+ Touch Evaluation Kit is pressed.
The application you create will utilize:
- Real-Time Clock (RTC) PLIB to periodically toggle the LED
- SERCOM (as Universal Synchronous Asynchronous Receiver Transmitter (USART)) PLIB with STDIO extension to print the LED toggling rate on a serial COM port terminal application running on a PC
- PORT PLIB to toggle the LED
- External Interrupt Controller (EIC) PLIB to change the periodicity of LED toggle and print using SWITCH press event
The lab will also demonstrate the use of callback functions.
Two Ways to Use This Tutorial
- Create the project from scratch:
- Use the provided source files and step-by-step instructions below.
- Use the solution project as an example:
- Build the solution project and program it to the PIC32CM GV-Value Line Curiosity Nano+ Touch Evaluation Kit to observe the expected behavior.
Lab Objectives
- Create an MPLAB X Integrated Development Environment (IDE) Harmony v3 project for a PIC32CM GV-VL microcontroller from scratch.
- Use MCC to configure and generate Harmony v3 PLIBs code for RTC, USART, EIC, and PORT peripherals.
- Use Harmony v3 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.
- Demonstrate the use of interrupt-driven callbacks to handle RTC and switch events in real time.
Reference Materials
- PIC32CM GV-Value Line Curiosity Nano+ Touch Evaluation Kit product page
- MPLAB X Integrated Development Environment (IDE)
Apart from the hardware tools listed above, the following items are required:
- USB Type-A male to USB Type-C® male cable for programming and debugging.
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.
Folder | Description |
---|---|
apps | Example applications for Chip Support Package (CSP) library components |
arch | Initialization and starter code templates and data |
docs | CSP library help documentation |
peripheral | PLIB templates and configuration data |
Connection Diagram
Connect the PIC32CM GV-Value Line Curiosity Nano+ Touch Evaluation Kit to the host PC as a USB device using a Type-A male to USB Type-C cable, with the Type-C end plugged into the Debug USB port. This debug USB port is used for debugging and powering up the device.
Overview
This lab shows you how to create an MPLAB Harmony v3 project from scratch, and how 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 USART peripheral
It demonstrates how to toggle an LED at regular intervals and display the current toggling rate on the serial terminal. The interval (timeout period) should cycle through 500 ms, 1s, 2s, 4s, and then return to 500 ms each time the mechanical switch on the PIC32CM GV VL Curiosity Nano+ Touch Evaluation Kit is pressed.
The application initializes the clock, PORT, and other peripherals (configured through MCC) by calling the function SYS_Initialize.
The application registers callback event handlers for RTC and EIC PLIBs. The callback event handlers are called back by the PLIBs when the RTC expires and LED sampling rate changes when the event occurs.
The application checks whether the configured RTC timer period has expired. Each time the timer period expires, the callback event handler sets a flag in the rtcEventHandler.
The application then clears the isRTCExpired flag, toggles the LED, and prints the LED toggling rate to the console.
The application also monitors the SW200 switch for user input. When a press is detected, it changes the LED toggle sampling rate from the default 500 ms to 1s. With each subsequent press, the sampling rate is updated to 2s, then 4s, and finally cycles back to 500 ms. The LED toggling rate is adjusted with every switch press, as illustrated in the accompanying image.
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.
- 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).
- The previous point is true because when created, an MPLAB 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:
- getting_started_pic32cm_gv_vl_cnano 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.
Procedure
Lab Index
Step 1: Create a Project and Configure the PIC32CM GV-VL CNANO
- Step 1 - Create MPLAB Harmony v3 Project Using MPLAB X IDE
- Step 2 - Verify Clock Settings
Step 2: Configure SERCOM 2 (USART) and RTC Peripheral Libraries
- Step 1 - Configure Real-Time Clock (RTC) Peripheral Library
- Step 2 - Configure SERCOM 2 (USART) Peripheral Library, STDIO Extensions and USART Pins
Step 3: Configure Pins for Switch and LED
- Step 1 - Configure Switch Button Pin with EIC to Generate an Interrupt
- Step 2 - Configure LED Pin
Step 4: Generate Code
Step 5: Add Application Code to the Project
Step 6: Build, Program, and Observe the Outputs