Update and Configure an Existing MHC-based MPLAB Harmony v3 Project to MCC-based Project

 Objective

This tutorial shows you how to update and configure an existing MPLAB Harmony Configurator (MHC)-based MPLAB Harmony v3 project to MPLAB Code Configurator (MCC)-based project. This training module uses the Getting Started Extended Application on Curiosity PIC32MZ EF 2.0 Development Board download to update and configure an existing project.

The application makes use of Curiosity PIC32MZEF v2 Development Board and I/O1 Xplained Pro Kit (optional if you intend to exercise the extended functionality described below).

Note: Though this application uses the PIC32MZEF microcontroller as an example, the general description and steps to install, configure, and generate code using MCC applies to all 32-bit PIC and SAM microcontrollers.

This application demonstrates an LED toggle (LED1 toggles when the switch SW1 is pressed and LED3 toggles when switch SW3 is pressed) on a timeout basis and prints the LED toggling rate on the serial terminal. The periodicity of the timeout will change from 500 milliseconds to one second, two seconds, four seconds, and back to 500 milliseconds every time you press the switch SW1 or SW3 on the Curiosity PIC32MZ EF 2.0 Development Board. The periodicity will not change while switching between SW1 to SW3 or vice versa.

The demo application has extended functionality to print the current room temperature periodically when switch SW2 is pressed (the Xplained pro extension connector on the Curiosity PIC32MZ EF 2.0 Development Board must be plugged with I/O1 Xplained Pro Extension Kit).

This application will utilize:

  • Timer Peripheral Library to periodically sample temperature sensor data and to toggle LED.
  • I2C Peripheral Library to read the temperature from a temperature sensor.
  • Universal Asynchronous Receiver Transmitter (UART), Direct Memory Access (DMA) Peripheral Libraries to print the temperature values on a COM (serial) port terminal application running on a PC.
  • GPIO Peripheral Library to toggle the LED.
  • Help develop your first MPLAB Harmony v3 application using MCC.

In the process, the lab will also demonstrate the use of callback functions.

Two Ways to Use this Tutorial

  1. Update and configure an existing project:
    • Use the provided source files and step-by-step instructions below.
  2. Use the solution project as an example:
    • Build the solution project and download it to the Curiosity PIC32MZ EF 2.0 Development Board to observe the expected behavior.

Lab Objectives

  1. Open and update an existing MHC-based project. i.e., Getting Started Extended Application on Curiosity PIC32MZ EF 2.0 Development Board using MCC.
  2. Configure and generate Harmony v3 Peripheral Libraries code for GPIO peripherals using the MCC.
  3. Extend the application code in the project, build, program, and observe the outputs.

 Materials

Hardware Tools

Tool About Purchase
board-50px.png
Curiosity PIC32MZ EF 2.0
Development Board
io1-xpro-extension-50px.png
I/O1 Xplained Pro
Extension Kit

The Curiosity PIC32MZ EF 2.0 Development Board includes a PICkit™ On Board 4 (PKOB4). No external tools are necessary to program or debug the PIC32MZ2048EFM144. For programming/debugging, the PKOB4 connects to the host PC through the USB Micro-B connector on the Curiosity PIC32MZ EF 2.0 Development Board.

Software Tools

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v5.50, MPLAB XC32 Compiler v3.00, and MPLAB Code Configurator v4.2.4

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.

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC32
C/C++ Compiler
swtool-28px.png
MPLAB® Code Configurator
Dynamic Code Generation

For this lab, download the following repositories from GitHub:

  • CSP - The following table shows the summary of contents.
Folder Description
apps Example applications for CSP library components
arch Initialization and starter code templates and data
docs CSP library help documentation
peripheral Peripheral library templates and configuration data
  • DEV_PACKS -The following table shows the summary of contents.
Folder Description
Microchip Peripheral register specific definitions
arm Core specific register definitions (CMSIS)
  • MHC - The following table shows the summary of contents.
File/Folder Description
doc Help documentation and licenses for libraries used
np_templates New Project templates for supported toolchains
*.jar Java implementations of MHC modules
mhc.jar Main Java executable (run: java -jar mhc.jar -h)
runmhc.bat Windows cmd batch file to run standalone MHC GUI

Note: mhc repo is still needed even if you are using the MCC plugin. The mhc repo contains the framework data.

Use the MPLAB Harmony v3 Framework downloader to download the repositories.

Overview

This lab shows you how to update and configure an existing MHC-based project to the MCC-based project. This lab:

  • shows you how to open an existing MHC project and migrate it to the MCC project,
  • verifies the existing MHC configuration on MCC,
  • configures the Pins for LED and Switch to extend the application,
  • generates the code,
  • extends the application code,
  • builds, and
  • program and observe the output.

It demonstrates an LED toggle (LED1 toggles when the switch SW1 is pressed and LED3 toggles when switch SW3 is pressed) on a timeout basis and prints the LED toggling rate on the serial terminal. The periodicity of the timeout will change from 500 milliseconds to 1 second, 2 seconds, 4 seconds, and back to 500 milliseconds every time you press the switch SW1 or SW3 on the Curiosity PIC32MZ EF 2.0 Development Board. The periodicity will not change while switching between SW1 to SW3 or vice versa. The demo application has extended functionality to print the current room temperature periodically when the XPRO connector is plugged with I/O1 Xplained Pro Extension Kit.


Figure 1: Application Flow Sequence
app_flow_chart.png

The application initializes the clock, GPIO, and other peripherals (configured through MCC) by calling the function SYS_Initialize.

The application registers callback event handlers for I²C, DMA, TMR, and GPIO PLIBs. The callback event handlers are called back by the PLIBs when the transaction completion events occur.

Note:
A callback event handler for UART is not registered as the actual UART data transfer, it is accomplished by the DMA. The DMA calls back the callback event handler when the DMA transfer request is completed.

The application checks whether the temperature read initiated, the configured timer (TMR1) period has expired, and the previous UART transmission is completed. If the temperature read is initiated then the application prints the read temperature value on the serial terminal else print LED toggling rate on the serial terminal on every timer period by initiating the DMA channel transfer function DMAC_ChannelTransfer for transmitting channel. The DMA PLIB calls back the registered callback event handler when the transmission completes. Finally, the application sets a flag in the TMR1 callback event handler.

The application also monitors the pressing of the switch SW1, SW2, and SW3; if SW2 switch press is detected, then the application reads temperature value and prints it on the serial terminal, toggles an LED (LED3 if SW3 is pressed else LED1), and prints the Sampling temperature rate on the serial terminal. If switch SW2 is not pressed then the application toggles an LED (LED3 if SW3 is pressed or LED1 if SW1 is pressed) and prints the LED toggling rate on the serial terminal. The periodicity of the timeout will change from 500 milliseconds to one second, two seconds, four seconds, and back to 500 milliseconds every time you press the switch SW1 or SW3 on the Curiosity PIC32MZ EF 2.0 Development Board. The periodicity will not change while switching between SW1 to SW3 or vice versa as shown in the following Figure 2.


Figure 2: State machine for the change in LED toggling rate
app_led_running_sequence.png
Table 1: Truth Table for the different switch press modes and the status of active LED
Mode Active LED
M1 LED1
M2 LED3
M3 LED1
M4 LED3

Note:

  • M1: Every subsequent pressing of the switch SW1 on the Curiosity PIC32MZ EF 2.0 Development Board changes the periodicity of the timeout from 500ms, to 1s, 2s, 4s, and back to 500s in cyclic order.
  • M2: There is no change in the LED toggle rate when switching from SW1 to SW3.
  • M3: There is no change in the LED toggle rate when switching from SW3 to SW1.
  • M4: Every subsequent pressing of the switch SW3 on the Curiosity PIC32MZ EF 2.0 Development Board changes the periodicity of the timeout from 500ms, to 1s, 2s, 4s, and back to 500s in cyclic order.

Lab Source Files and Solutions

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

Place the contents of this ZIP file in:

<Any directory of your choice>/training/
(example Directory = C:/microchip/harmony/v3.3.0)

Note:

  1. The project location of a Harmony v3 project is independent of the location of the Harmony v3 Framework path (i.e., you need not create or place a Harmony v3 project in a relative path under the Harmony v3 framework folder). The project can be created or placed in any directory of your choice.
  2. The point above is to be noted because when a Harmony v3 project is created, it generates all the referred source/header files and libraries (if any) under the project folder.
  3. Both the points above contrast with the Harmony v2 project location. In Harmony v2, the project was supposed to be created in a location under the Harmony v2 framework.


Extracting the ZIP file creates the following folders:

  • getting_started_ext contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
    • dev_files contains subfolder pic32mz_ef_curiosity_v2 containing application source files and other support files (if any) required to perform the lab (see "Procedure" section below).
    • firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behavior.

Install MPLAB Code Configurator from the Microchip Plugins Update Center

If this is the first time you are using MCC to create an MPLAB Harmony v3 project, follow the instructions below. Otherwise, skip to the "Procedure" section.

Install MPLAB Code Configurator (MCC).

1

Launch MPLAB X IDE from the Microsoft Windows® Start menu. Close any projects and files that are currently open.

Make sure you are using MPLAB X IDE version v5.45 or higher.

2

Go to Tools > Plugins.

3

You will see the Microchip Plugins Update Center window open.

plugins_update_cneter.png

4

Now, go to Available Plugins, select MPLAB® Code Configurator, and click on the Install button at the down left corner of the Plugins window.

select_and_install_mcc.png

5

Click the Next button when the Plugin Installer prompts.

next_button_prompt.png

6

Accept "License Agreement" when the Plugin Installer prompts and click on the Install button.

license_agreement.png
plugin_installing_process.png

7

Choose Restart Now and click the Finish button when the Plugin Installer prompts.

restart_now.png

If you would like to install a specific version of the MCC plugin, you can download the particular MCC plugin file and follow the above steps except for the fourth step. In place of the fourth step, go to Downloaded > Add Plugins, select and open the specific version of the MCC plugin (NBM) file from your downloads.

specific_ver_mcc.png
open_nbm_file.png

Procedure

All steps must be completed before you will be ready to build, download, and run the application.

Lab Index

Step 1: Open the existing MHC project and migrate it to the MCC project

  • Step 1.1 - Open MPLAB Harmony v3 Project on MPLAB X IDE
  • Step 1.2 - Migrate to MCC project
  • Step 1.3 - Verify the Clock Settings

Step 2: Verify the existing MHC configuration on MCC

  • Step 2.1 - Verify the UART, I2C, DMA, and TMR peripheral configurations
  • Step 2.2 - Verify the Switch and LED pin configurations

Step 3: Configure Pins for Switch and LED to extend the application

  • Step 3.1 - Configure the Switch button pin
  • Step 3.2 - Configure the LED Pin

Step 4: Generate code
Step 5: Extend the application code in the project
Step 6: Build, program and observe the outputs

© 2021 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.