Migrating ASF SAM C21 Application to MPLAB Harmony v3 PIC32CM MC

MPLAB® Harmony v3 is now configurable through MPLAB Code Configurator (MCC). Although the instructions in this tutorial are for the MHC, the flow and experience of creating a project, configuring peripherals, and generating code using MCC are similar. Refer to the links below for specific instructions to use MPLAB Harmony v3 with MCC.

 Objective

This tutorial shows you how to migrate an application from Advanced Software Framework (ASF) to MPLAB Harmony v3 software framework using 32-bit Arm® Cortex®-based M0+ PIC32CM MC microcontroller.

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 Harmony Configurator (MHC) 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.

The application makes use of the PIC32CM MC Curiosity Development Board and the I/O1 Xplained Pro Extension Kit (sold separately).

This tutorial will migrate a pre-developed ASF SAMC21 IO1 Xplained demo application available in Atmel START.

The application reads the current room temperature from the temperature sensor and light level from the light sensor on the I/O1 Xplained Pro Extension and sends it to the console.

asf_demo.PNG

This training module will implement the same application and will also demonstrate the callback feature.

The application you create will utilize:

  • SERCOM (as I²C) PLIB to read the temperature from a temperature sensor.
  • SERCOM (as Universal Synchronous Asynchronous Receiver Transmitter (USART)) PLIBs and STDIO library to print the temperature values on a COM (serial) port terminal application running on a PC.
  • The ADC peripheral library is used to read data from the light sensor.

There are two approaches for 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 PIC32CM MC Curiosity Development Board to observe the expected behavior.

Lab Objectives

  1. Create an MPLAB X IDE Harmony v3 project for a PIC32CM MC MCU from scratch.
  2. Use MHC to configure and generate Harmony v3 Peripheral Library code for I²C, USART, and ADC peripherals.
  3. Use the Harmony v3 Peripheral Library Application Programming Interfaces (APIs) to implement the application.

 Materials

Hardware Tools

Tool About Purchase
board-50px.png
PIC32CM MC00 Curiosity Pro
Development Board
ATIO1-XPRO-50px.png
I/O1 Xplained Pro
Extension Kit

The Curiosity series evaluation kits include an onboard Embedded Debugger (EDBG). No external tools are necessary to program or debug the PIC32CM1216MC00048. For programming or debugging, the EDBG connects to the host PC through the USB micro-B connector on the PIC32CM MC Curiosity Development Board.

Software Tools

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v5.40
MPLAB XC32 Compiler v2.41
MPLAB Harmony CSP v3.8.1
DEV_PACKS v3.8.0
MHC v3.5.1

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

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 Graphical User Interface (GUI)

Overview:

This lab shows you how to create an MPLAB Harmony v3 project from scratch. You will configure and generate Harmony v3 peripheral library code for the I²C, USART, and ADC peripherals by considering the SAMC21 ASF example application.

The application flow is as follows:

  • The application registers as an I²C callback with a temperature sensor and submits a request to read the temperature value.
  • I²C notifies the application with an event after successfully reading the temperature.
  • The application converts the temperature value read from the sensor to a readable format (Fahrenheit).
  • Meanwhile, ADC is enabled to read and convert the light sensor value from the light sensor on the IO1 Xplained Pro board.
  • After the ADC conversion, the temperature and light sensor value are printed on the console continuously.
flowchart.png
Figure 1. Application Initialization flow sequence

Lab Source Files and Solutions

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

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

  • The project location of a Harmony v3 project is independent of the location of the Harmony 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. This 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.
  • The point above contrasts with the Harmony v2 project location. In Harmony v2, the project was supposed to be created in a location under the Harmony framework.


Extracting the ZIP file creates the following folders:

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

Procedure

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

Lab Index

Step 1: Create Project and Configure the PIC32CM MC

  • Step 1.1 - Verify Whether MHC Plug-in is Installed in MPLAB X IDE
  • Step 1.2 - Create MPLAB Harmony v3 Project Using MPLAB X IDE
  • Step 1.3 - Configure Clock Settings

Step 2: Configure I²C, USART, and STDIO

  • Step 2.1 - Configure I²C Peripheral Library, and I²C Pins
  • Step 2.2 - Configure USART Peripheral Library, STDIO, USART Pins, and link STDIO library

Step 3: Configure ADC

  • Step 3.1 - Configure Analog-to-Digital Converter (ADC) Peripheral Library (PLIB)
  • Step 3.2: Configure Supply controller (SUPC)

Step 4: Generate Code

Step 5: Add Application Code to the Project

Step 6: Build, Program, and Observe the Outputs



First Step >

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