Create a new MPLAB Harmony v3 project using MCC

 Objective

This tutorial shows you how to create a new MPLAB Harmony v3 project using MPLAB Code Configurator (MCC). This training module used SAM D5x/E5x MCUs to create an application that gets you started in developing applications using MCC on the MPLAB Harmony v3 software framework.

The application makes use of SAM E51 Curiosity Nano Evaluation Kit.

Note: Though this application uses the SAM E51 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 (LED0) toggle 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 SW0 on the SAM E51 Curiosity Nano Evaluation Kit.

The applications you create will utilize:

  • Real-Time Clock (RTC) PLIB to periodically sample temperature sensor data.
  • SERCOM (as USART), Direct Memory Access (DMA) PLIBS to print the temperature values on a COM (serial) port terminal application running on a PC.
  • PORT PLIB 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. Create the project from scratch:
    • 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 SAM E51 Curiosity Nano Evaluation Kit Board to observe the expected behavior.

Lab Objectives

  1. Create an MPLAB X IDE Harmony v3 project for a SAM E51 microcontroller from scratch.
  2. Use the MCC to configure and generate Harmony v3 Peripheral Libraries code for RTC, USART, DMA, and PORT peripherals.
  3. Use the Harmony v3 PLIB Application Programming Interfaces (APIs) to implement the application.

 Materials

Hardware Tools

Tool About Purchase
board-50px.png
SAM E51 Curiosity Nano Evaluation Kit
EV76S68A

The Curiosity Nano Evaluation series kits include an "on-board" debugger as a hardware tool to program and debug the application. No external tools are necessary to program or debug the ATSAME51J20A. For programming and debugging, the on-board debugger connects to the host PC through the USB Micro-B connector on the SAM E51 Curiosity Nano Evaluation Kit.

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.0

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 difinitons (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 you are using 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 create an MPLAB Harmony v3 project from scratch using MCC. It shows you how to configure, and generate Harmony v3 Peripheral Libraries code for RTC, USART, DMA, and PORT peripherals. It demonstrates an LED (LED0) toggle 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 SW0 on the SAM E51 Curiosity Nano Evaluation Kit.


Figure 1.1 Application Flow Sequence

The application initializes clock, PORT, and other peripherals (configured through MCC) by calling the function SYS_Initialize.
The application registers callback event handlers for DMA, RTC, and External Interrupt Controller (EIC) Peripheral Libraries. The callback event handlers are called back by the peripheral libraries when the transaction completion events occur.
Note:

  1. A callback event handler for SERCOM (as USART) is not registered as the actual USART data transfer is accomplished by the DMA. The DMA calls back the callback event handler when the DMA transfer request is completed.
  2. RTC peripheral is used for implementing the time period instead of the timer peripheral. This is done to demonstrate how to configure and use RTC peripheral in an application (particularly low power application).

The application checks whether the configured RTC timer period has expired and checks the previous USART transmission completed. The application prints the 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 RTC callback event handler.

app_flow_sequence.png
Figure 1.1 shows the flow sequence of the application task.
Click image to enlarge.

The application also monitors the pressing of the switch SW0; if a switch press is detected, the application changes the LED toggling rate from the default 500 milliseconds to 1 second. The application changes the LED toggling rate to 2 seconds, 4 seconds, and back to 500 milliseconds on subsequent switch press. Thus, the application cycles the LED toggling rate on every switch press.

app_led_running_sequence.png

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:

  • same51n_getting_started contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
    • dev_files contains subfolder sam_e51_cnano 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 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 Plugin Installer prompts.

next_button_prompt.png

6

Accept "License Agreement" when 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 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: Create project and configure the MCU

  • Step 1.1 - Create MPLAB Harmony v3 Project using MCC on MPLAB X IDE
  • Step 1.2 - Verify Clock Settings

Step 2: Configure 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
  • Step 3.2 - Configure LED Pin
  • Step 3.3 - Rename the default main file

Step 4: Generate Code
Step 5: Add application code to the project
Step 6: Build, program and observe the outputs

© 2024 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.