3.5.3 AC Sleepwalking Application Built with GCC Toolchain on SAM D21 Xplained Pro Kit
Description
This application demonstrates how to use the AC (Analog Comparators) Peripheral library to perform a single-shot conversion when the peripheral is triggered by the RTC (Real-Time Counter) compare event. The generation of a trigger and compare operation is done while the CPU is in the standby sleep mode. The AC generates the interrupt at the end of the comparison which wakes the CPU.
The application demonstrates to build an MPLAB Harmony v3 project with Arm GNU Toolchain in MPLABX IDE. The page demonstrates configuring, building, and running an MPLAB Harmony v3 peripheral library (PLIB) based application with the Arm GCC toolchain developed on the SAM D21 Xplained Pro Evaluation Kit.
Modules/Technology Used
- Peripheral Modules
- AC
- PORTS
- RTC
- PM (Power Manager)
- SERCOM (USART)
Hardware Used
Software/Tools Used
This project has been verified to work with the following versions of software tools:
Refer Project Manifest present in harmony-manifest-success.yml under the project folder firmware/src/config/sam_d21_xpro.
- Refer the Release Notes to know the MPLAB X IDE and MCC Plugin version.
- Any Serial Terminal application, such as Tera Term terminal application.
Because Microchip regularly updates tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project does not seem to work and version incompatibility is suspected. It is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB Harmony v3 packages, refer to document How to Use the MPLAB Harmony v3 Project Manifest Feature (DS90003305).
Setting up SAM D21 Xplained Pro Evaluation Kit
- Connect a voltage below VDD to pin 17 of the EXT1 connector.
- Connect the Debug USB port on the board to the computer using a micro USB cable.
Prerequisite
- Download and install Arm GNU Toolchain v6.3.1.Note: If Atmel Studio is already installed in PC, then installing Arm GCC toolchain is not required as Atmel Studio is already bundled with Arm GNU Toolchain.
Configure the Project to Use Arm GCC Toolchain
This can be done with two methods, either automatically or manually.
- Automatic Detection: If Atmel Studio is
installed in PC, By default, MPLAB X IDE detects the Arm GCC toolchain (installed as a
part of Atmel Studio) and shows it in the MPLAB X IDE's Project properties.
Since the Arm GCC toolchain is already available, switch to the Arm GCC toolchain from the project properties.
- Manual: If Atmel Studio is not
installed, install the Arm GCC toolchain manually.
Go to MPLAB X IDE -> Tools -> Options -> Embedded -> Build Tools -> Add -> give the base directory -> Enter the path of “xx/xxx/toolchain/arm/arm-gnu-toolchain\bin”. Save it.
- Select the Arm GCC toolchain in the
project properties. Select the Project -> Right Click -> Properties -> select
the Arm GCC toolchain in compiler options and save.
Programming Hex File
The pre-built hex file can be programmed by following the below steps.
- Open MPLAB X IDE.
- Close all existing projects in IDE, if any project is opened.
- Go to File -> Import -> Hex/ELF File.
- In the Import Image File
window,
- Create Prebuilt Project,
- Click the Browse button to select the prebuilt hex file.
- Select Device as ATSAMD21J18A.
- Ensure the proper tool is selected under Hardware Tool and click on Next button.
- Select Project Name and Folder,
- Select appropriate project name and folder and click on Finish button
- Create Prebuilt Project,
- In MPLAB X IDE, click on Make and Program Device button to program the device.
- Follow the steps in Running the Demo section below.
Programming/Debugging Application Project
- Open the project (sam_d21_xpro\samd21_ac_sleepwalk_singleshot_gcc\firmware\sam_d21_xpro.X) in MPLAB X IDE
- Ensure SAM D21 Xplained Pro is selected as hardware tool to program/debug the application
- Build the code and program the device by clicking on the Make and Program Device button in MPLAB X IDE tool bar
- Follow the steps in Running the Demo section below
Running the Demo
- Perform Prerequisite, Configure the project to use Arm GCC Toolchain and Setting up SAM D21 Xplained Pro Evaluation Kit steps mentioned above, if not done already.
- Open the Tera Term terminal application on the PC from the Windows Start menu by pressing the Start button.
- Connect to the EDBG Virtual COM port and configure the baud rate to 115200.
- Build and Program the application using the MPLAB X IDE.
- The console displays the message stating whether voltage at PA04 is lower or greater than the internal bandgap voltage (1.1V).
- LED0 toggles when comparison is
done.
Comments
- Reference Guide: Build MPLAB Harmony v3 project with Arm GCC toolchain in MPLAB X IDE
- Reference Training Module: Getting Started with Harmony v3 Peripheral Libraries on SAM D21 MCUs
- This application demo builds and
works out of box by following the instructions above in Running the Demo
section. If the user needs to enhance/customize this application demo, should use the
MPLAB Harmony v3 Software framework. Refer links below to setup and build the
applications using MPLAB Harmony.
- How to Setup MPLAB Harmony v3 Software Development Framework (DS90003232).
- How to Build an Application by Adding a New PLIB, Driver, or Middleware to an Existing MPLAB Harmony v3 Project (DS90003253).
- Video - How to Set up the Tools Required to Get Started with MPLAB® Harmony v3 and MCC
- Create a new MPLAB Harmony v3 project using MCC
- Update and Configure an Existing MHC-based MPLAB Harmony v3 Project to MCC-based Project