Migrating ASF SAM C21 Application to MPLAB® Harmony v3 PIC32CM MC

Last modified by Microchip on 2024/06/24 06:31

 

Warning: This tutorial uses the old Harmony configuration tool (MPLAB® Harmony Configurator (MHC)). New Harmony projects should use the MPLAB Code Configurator (MCC) instead.

 

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 details

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:

  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

Reference Materials

About

Purchase

Tool

Information

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.

Hardware Setup

Connect the hardware as follows:

  • Connect the I/O1 Xplained Pro extension kit to the Extension Header 1 (EXT1) of the PIC32CM MC Curiosity Development Board.
  • Connect a USB cable to the DEBUG USB port for programming.

 

Hardware setup

Software Tools

 

Information

This project has been verified to work with the following versions of software tools:

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.

For this lab, download the following repositories from GitHub:

  • CSP: The following table shows the summary of contents.
FolderDescription
appsExample applications for CSP library components
archInitialization and starter code templates and data
docsCSP library help documentation
peripheralPeripheral library templates and configuration data
  • DEV_PACKS: The following table shows the summary of contents.
FolderDescription
MicrochipPeripheral register specific definitions
armCore Specific Register Definitions (CMSIS)
  • MHC: The following table shows the summary of contents.
File/FolderDescription
docHelp documentation and licenses for libraries used
np_templatesNew Project templates for supported toolchains
*.jarJava implementations of MHC modules
mhc.jarMain Java executable (run: java -jar mhc.jar -h)
runmhc.batWindows 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.

 

Application Initialization flow sequence

Lab Source Files and Solutions

Information

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.

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

Information

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