Low Power Application on SAM E54 (Arm® Cortex®-M4) MCUs Using MPLAB® Harmony v3 Peripheral Libraries

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

Objective

This tutorial shows you how to create a low power application on a SAM E54 using the MPLAB® Harmony v3 software framework.

The SAM E54 is a 32-bit Arm® Cortex®-M4 based microcontroller that provides features to reduce power consumption through different sleep modes, such as Idle, Standby, Backup, Hibernate, and Off.

  • In Idle mode, the CPU and the synchronous clocks are stopped, except when requested. This mode allows power optimization with a fast wake-up time.
  • In Standby mode, the CPU and the peripherals are stopped, except those that are running using the Run in Standby mode feature. This mode allows the device to consume the lowest power with little overhead on wake-up time.
  • In Backup mode, the device is entirely powered off, except for the peripherals in the backup domain. This mode allows you to achieve the lowest power consumption aside from Off mode but increases the wake-up time compared to Standby mode.
  • In Hibernate mode, the device is entirely powered off, except for the peripherals in the Hibernate mode. This mode allows you to achieve the lowest power consumption but a little more than Backup mode and wake-up time are a little faster than Backup mode.
  • In Off mode, the device is entirely powered off. This mode allows you to achieve the lowest power consumption. Since the device must be reset to recover from this mode, the wake-up time is longer.

The Power Manager (PM) module is responsible for controlling the Low Power modes. Additionally, the SAM E54 provides SleepWalking, an advanced Low Power Operation mode, which is based on event propagation managed by the Event System (EVSYS).

The application makes use of the SAM E54 Xplained Pro Evaluation Kit and the I/O1 Xplained Pro Extension Kit (sold separately).

The application is developed on the MPLAB Harmony v3 software framework. MPLAB Harmony is a modular framework that provides interoperable firmware libraries for application development on 32-bit MCUs and MPUs. It includes an easy-to-use Graphical User Interface (GUI) (MPLAB Code Configurator (MCC)) for selecting, configuring, and generating starter codes, peripheral libraries, and middleware (USB, TCP/IP, graphics, and so on).

On power-up, the device is set to Standby mode. The device wakes up from Standby mode and enters Active mode when you cover the light sensor (by placing a hand over it, for example) on the I/O1 Xplained Pro extension kit. The application periodically prints the room temperature on a serial terminal while the light sensor is covered. The device goes back to Standby mode when you uncover the light sensor. LED0 on the SAM E54 evaluation kit is toggled every time the temperature is displayed on the serial console. When you press the switch button SW0, the application switches Sleep mode from Standby mode to Idle mode.

The application you create will utilize the following peripherals:

  • SERCOM3 (as I²C) peripheral library to read the temperature from the temperature sensor.
  • Real-Time Clock (RTC) peripheral library to periodically generate an event for the ADC to sample the light sensor.
  • SERCOM2 (as Universal Synchronous Asynchronous Receiver Transmitter (USART)) peripheral library to print messages on a serial console running on a computer.
  • Direct Memory Access Controller (DMAC) peripheral library to send the converted temperature value to the SERCOM0.
  • PORT peripheral library to toggle the LED0.
  • Analog-to-Digital Converter (ADC1) peripheral library to sample the light sensor analog input and detect whether the light sensor is covered or not.
  • PM and Supply Controller (SUPC) peripheral libraries to configure Low Power modes.
  • External Interrupt Controller (EIC) peripheral library to control the user button SW0.
  • EVSYS peripheral library to trigger the start of the ADC conversion on every RTC compare match event. The EVSYS allows for peripheral-to-peripheral communication without CPU intervention. This reduces the burden on the CPU and other resources when compared to conventional interrupt-based systems.

Back to Top

Two Ways to Use This Tutorial

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 SAM E54 Xplained Pro evaluation kit to observe the expected behavior.

Back to Top

Lab Objectives

  1. Create an MPLAB Harmony v3 project for a SAM E54 MCU from scratch.
  2. Use MCC to configure and generate MPLAB Harmony v3 Peripheral Library code for RTC, I²C, USART, Direct Memory Access (DMA), ADC, PM, SUPC, EIC, EVSYS, and PORT peripherals.
  3. Use the MPLAB Harmony v3 Peripheral Library Application Programming Interfaces (APIs) to implement and demonstrate a low power application.

Back to Top

Materials

Reference Materials


About

SAM E54 Xplained Pro Evaluation Kit

I/O1 Xplained Pro Extension Kit

Purchase

Part Number: ATSAME54-XPRO - SAM E54 Xplained Pro

Part Number: ATIO1-XPRO - I/O1 Xplained Pro extension kit

Tool

MPLAB X Integrated Development Environment (IDE)

MPLAB XC32 C/C++ Compiler

Information

The Xplained Pro series evaluation kits include an onboard Embedded Debugger (EDBG). No external tools are necessary to program or debug the ATSAME54P20A. For programming or debugging, the EDBG connects to the host PC through the USB Micro-B connector on the SAM E54 Xplained Pro evaluation kit.

Back to Top

Hardware Connection Setup

  • Connect the I/O1 Xplained Pro extension kit to the Extension Header 1 (EXT1) of the SAM E54 Xplained Pro evaluation kit.
  • Connect a USB cable to the DEBUG USB port for programming.
Information

Make sure common ground is connected with the board while using the logic analyzer or CRO.

Hardware Setup

Figure: Hardware Setup

Back to Top

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)
  • Use the MPLAB Code Configurator (MCC) to download the repositories. 

Overview

This lab shows you how to create an MPLAB Harmony v3 project from scratch. You will configure and generate MPLAB Harmony v3 peripheral library code for the RTC, I²C, USART, ADC, DMA, PM, SUPC, EIC, EVSYS, and PORT peripherals. It also demonstrates Low Power mode features of the SAM E54 MCU using light and temperature sensors on the I/O1 Xplained Pro extension kit.The application flow is as follows:

On power-up, the application runs in Standby mode.
The RTC is configured as an event generator to generate a periodic (every 500 ms) event to trigger the ADC to start conversion.
The ADC acknowledges the event from the RTC and starts the conversion of the light sensor signal.
If the ADC conversion result is greater than the defined threshold, the ADC produces an interrupt to wake up the CPU.
In Active mode, the CPU submits an I²C read transfer request to read the temperature value from the temperature sensor on the I/O1 Xplained Pro evaluation kit.
The application submits a DMA transfer request to transfer the latest temperature value (in a formatted message) to the USART (serial console).
After the DMA transfer is complete, the device re-enters Standby mode.

Application Initialization flow sequence

Figure: Application Initialization flow sequence

The application also monitors the pressing of the switch SW0. If a switch press is detected, the application moves the device to Idle Sleep mode. As in Standby mode, covering the light sensor with your hand wakes up the device from Idle Sleep mode. Once awake, the application prints room temperature values on the serial console and re-enters Standby Sleep mode once the light sensor is uncovered.

CPU in Idle or Standby mode

Figure: CPU in Idle or Standby mode

Back to Top

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 on this page).

Information

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

  • The project location of an MPLAB Harmony v3 project is independent of the location of the MPLAB Harmony Framework path (i.e., you need not create or place an MPLAB 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 MPLAB Harmony v2 project location. In MPLAB Harmony v2, the project was supposed to be created in a location under the Harmony framework.

Back to Top

ZIP

  Windows
  Linux
  Mac®

Extracting the ZIP file creates the following folders:

  • same54_low_power contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
    • dev_files contains subfolder sam_e54_xpro which contains 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.

Back to Top

Procedure

Information

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

Back to Top

Lab Index

Step 1: Create Project and Configure the SAM E54

  • Create MPLAB Harmony v3 Project using MPLAB X IDE

  • Configure Clock Settings

Step 2: Configure I²C, USART, and RTC Peripheral Libraries

  • Configure RTC Peripheral Library

  • Configure I²C Peripheral Library, I²C Pins, and Verify I²C Clock

  • Configure USART Peripheral Library, USART Pins, and Verify USART Clock

  • Configure DMA Peripheral Library

Step 3: Configure ADC, Event System, and EIC Peripheral Libraries

  • Configure Analog-to-Digital Converter (ADC) Peripheral Library (PLIB)

  • Configure External Interrupt Controller (EIC) PLIB for Switch Button

  • Configure Event System (EVSYS) PLIB

Step 4: Configure PM, SUPC and NVMCTRL Peripheral libraries and LED Pin

  • Configure Power Manager (PM) Peripheral Library

  • Configure SUPC Peripheral Library

  • Configure NVMCTRL Peripheral Library

  • Configure LED Pin

  • Rename the Default Main File

Step 5: Generate Code

Step 6: Add Application Code to the Project

Step 7: Build, Program, and Observe the Outputs

Back to Top