Low Power Application on SAM D21 Using Harmony v3 Peripheral Libraries: Step 1

Last modified by Microchip on 2023/11/09 09:07

Verify whether the MHC Plug-in is Installed in MPLAB® X IDE
Verify that MPLAB® Harmony Configurator (MHC) is installed.
  • Launch the MPLAB X IDE from the Microsoft Windows® Start menu. Close any projects and files that are currently open.
  • Go to Tools > Embedded.
  • You will see MPLAB Harmony 3 Configurator in the menu.

mhc launch setup

If you don't see it in the menu, install MHC.

Back to top


Set Up MHC Plug-in Window to Open in Standalone Mode
Go to Tools > Options. You will see the Options window open.

Options window openOptions window open

Go to Plugins > Window Manager and select Standalone mode. Click Apply and then click OK.

Going to Plugins > Window Manager and selecting Standalone mode​​​​​

  • When you launch MHC for the first time, it displays a prompt asking for the mode in which you would like to use MHC.
    • Standalone mode (as a separate window)
    • Native mode (as an embedded window in MPLAB X)
  • Standalone mode is the default mode.
  • MHC will launch in the operating mode selected the first time, every time you launch MHC.
  • Step 1.2 above shows a way to change the MHC operating mode.

For this lab, MHC is configured to operate in Standalone mode.

Back to top


Create MPLAB Harmony v3 Project Using MPLAB X IDE
Select File > New Project from the main IDE menu.

Close all existing opened projects before you start creating a new project.

In the Categories pane of the New Project dialog window, select Microchip Embedded. In the Projects pane, select 32-bit MPLAB Harmony v3 Project, then click Next.

Categories pane of the New Project dialog window​​​​​

If 32-bit MPLAB Harmony 3 Project is not displayed, install MHC. 

Browse to the folder you downloaded the framework to in the Framework Path edit box. If you haven't done this, or want to download it to a different folder, click the Launch Content Manager button, then click Next.

For more information on the content manager, see the "Download MPLAB Harmony Framework" section of the "MPLAB Harmony Configurator Overview" page.

New Project window

In the Project Settings window, apply the following settings:
  • Location: Indicates the path to the root folder of the new project. All project files will be placed inside this folder. The project location can be any valid path, for example: <Your_folder>\dev\samd21_low_power.
  • Folder: Indicates the name of the MPLABX .X folder. Enter "sam_d21_xpro" to create a sam_d21_xpro.X folder.
  • Name: Indicates the name of the project that will be shown in MPLAB X IDE. Enter "low_power_sam_d21_xpro" to set the project's name.

Note: The Path box is read-only. It will update as you make changes to the entries.

  • Click Next to proceed to Configuration Settings.

Configuration Settings​​​​​

Clicking on the Show Visual Help button will open a help window, providing a detailed description of the various fields in the Project Settings window.

New Project Wizard Help

Follow the steps below to set the project’s Configuration Settings.
  • Name: Enter the configuration name as "sam_d21_xpro".
  • Target Device: Select ATSAMD21J18A as the target device.

Note: You can select the Device Family or enter a partial device name to filter the list in Target Device to make it easier to locate the desired device.

After selecting the target device, click Finish to launch the MHC. 

Clicking Finish to launch the MHC​​​​​

The New Project Wizard opens a Configuration Database Setup window to allow you to review the packages that will be used by the current project.

Click Launch to launch the MHC tool with the selected packages.

Clicking Launch to launch the MHC tool with the selected packages The MHC plugin’s main window for the project will be displayed.

The MHC plugin’s main window for the project

Before proceeding, set up the compiler toolchain. Click on the Projects tab on the top left pane in MPLAB X IDE. Right-click on the project name low_power_sam_d21_xpro and go to Properties.

The Projects tab on the top left pane in MPLAB X IDE​​​​​

Tool Tip:
You can also open the Project Properties by selecting the project from the Projects tab and File > Project Properties from the main IDE menu.

Make sure that XC32 (v3.00) is selected as the Compiler Toolchain for XC32. Click on Apply and then click on OK.

Selecting as the Compiler Toolchain for XC32​​​​​

 When configuring the compiler toolchain, make sure to select the latest device SAMD21_DFP version.

Tool Tip:
If you closed MHC accidentally and would like to open it again, go to Tools > Embedded > MPLAB Harmony 3 Configurator in MPLAB X IDE. 

Back to top


Configure Clock Settings
Launch Clock Easy View by going to the Tools menu of the MHC window and then selecting Clock Configuration.

Launching Clock Easy View

A new window, Clock Easy View, is opened inside MHC.

The Clock Easy View window will then appear on your screen. The default CPU clock is set to 48 MHz.

The default CPU clock is set to 48 MHz

Tool Tip:

  • The Clock Easy View window can be minimized by clicking the minimize button.

Minimize View

  • After minimizing the Clock Easy View window, you can see a small Clock Easy View tab at the bottom-left in MHC.

Clock Easy View

  • The Clock Easy View window can be maximized by clicking the maximize button or by double-clicking on the Clock Easy View window.

Maximize View

  • These tips apply to all other plug-in managers like Pin Configuration, DMA Configuration, Event System Configuration, and EVIC Configuration.
Enable and configure the 32K Crystal Oscillator. Click on the Settings (wheel) button and enable the Run Oscillator in Standby Sleep Mode.

Enabling and configuring the 32K Crystal OscillatorEnabling and configuring the 32K Crystal Oscillator

Enable GCLK2 and set XOSC32K as the GCLK2 clock source. Click on the Settings (wheel) button and enable the Run GCLK2 in Standby Sleep Mode.

Enabling GCLK2 and setting XOSC32K as the GCLK2 clock sourceEnabling GCLK2 and setting XOSC32K as the GCLK2 clock source

Enable and configure the Digital Frequency Locked Loop (DFLL).

Enabling and configuring the Digital Frequency Locked Loop (DFLL)Check the CPU clock, now CPU clock is set to 47,972,352 Hz as the DFLL configuration changed.

​Checking the CPU clock

Enable GCLK1 and set OSCULP32K as the GCLK1 clock source. Set the GCLK1 output frequency as 1 kHz by configuring the division factor with 32. Click on the Settings (wheel) button and check the box for GCLK should keep running in Standby mode.

 Enabling GCLK1 and setting OSCULP32K as the GCLK1 clock source Enabling GCLK1 and setting OSCULP32K as the GCLK1 clock source

Back to top