Migrating ASF SAM C21 Application to MPLAB® Harmony v3 PIC32CM MC
Contents
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.
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.
Tutorial Approaches
There are two approaches for 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 download it to the PIC32CM MC Curiosity Development Board to observe the expected behavior.
Lab Objectives
- Create an MPLAB X IDE Harmony v3 project for a PIC32CM MC MCU from scratch.
- Use MHC to configure and generate Harmony v3 Peripheral Library code for I²C, USART, and ADC peripherals.
- Use the Harmony v3 Peripheral Library Application Programming Interfaces (APIs) to implement the application.
Materials
Reference Materials
About
Purchase
- Part Number: EV15N46A - PIC32CM MC00 Curiosity Pro Evaluation Kit
- Part Number: ATIO1-XPRO - I/O1 Xplained Pro extension kit
Tool
Hardware Setup
Software Tools
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) |
- Use the MPLAB Harmony 3 Content Manager (MHCM) to download the repositories.
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.
Lab Source Files and Solutions
ZIP
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
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.1 - Configure Analog-to-Digital Converter (ADC) Peripheral Library (PLIB)
Step 3.2: Configure Supply controller (SUPC)