Link Search Menu Expand Document

                                                                                                     

Build MPLAB Harmony v3 project with ARM GCC toolchain in MPLAB X IDE

This page describes steps 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) application with the ARM GCC toolchain developed on the SAM D21 Xplained Pro Evaluation Kit.

The 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 SAM D21 Xplained Pro Evaluation Kit is ideal for evaluating and prototyping with the SAM D21 ARM® Cortex®-M0+ based microcontrollers. Xplained Pro Extension kits compatible with SAM D21 Xplained Pro can be purchased individually.

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 quickly and easily develop powerful and efficient embedded software for Microchip’s 32-bit PIC® and SAM devices.

Prerequisite:

There are two ways to use this guide:

  1. Use the solution project as an example:
  2. Create the project from scratch:
    • Follow step-by-step instructions below.

Instructions to configure, build and run MPLAB Harmony v3 project with ARM GCC toolchain in MPLAB X IDE

The following bullet points provides links to the topics:

Hardware Used:

Software/Tools Used:

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

Because Microchip regularly update tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project doesn’t 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.

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

Description

Overview:

The AC Sleepwalking Harmony v3 Application on SAM D21 Xplained Pro Evaluation Kit is used to show the steps to compile the project with ARM GCC Toolchain in MPLAB X IDE.

Note: The AC Sleepwalking demo application is chosen as an example. The user could chose to use any MPLAB Harmony v3 application developed on MPLAB X IDE to be built with the ARM GCC toolchain.

Open project and compile using XC32 Toolchain:

Note: This is an optional step. This could be followed to verify whether the existing Harmony v3 example used in this guide builds and works on the XC32 compiler toolchain.

  • Open MPLAB X IDE and close if any projects are opened.
  • Go to File -> Open Project -> <Go to Harmony v3 repository> -> csp_apps_sam_d21_da1 /apps/ac/ac_sleepwalk_singleshot/firmware and select the “sam_d21_xpro.X” and open the project.
  • Before changing the toolchain to ARM GCC, ensure the example application demo is compiling and working fine with existing the XC32 toolchain. This is to avoid any errors because of missing library or source files.
  • Select the Project -> Right Click -> Properties -> ensure correct hardware and XC32 compiler version is selected.
  • Compile the project.
  • Run on hardware to ensure the project is working as expected.

Configure the project to use ARM GCC Toolchain:

This can be done with two methods, either automatically or manually.

  1. 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. Refer the figure which shows ARM GCC Toolchain selection. Since the ARM GCC toolchain is already available, switch to the ARM GCC toolchain from the project properties.
  2. 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 -> **/toolchain/arm/arm-gnu-toolchain/bin"**. Save it.
    • Now, select the ARM GCC toolchain in the example application demo project properties. Select the Project -> Right Click -> Properties -> select the ARM GCC toolchain in compiler options and save.

Compile the project using ARM GCC Toolchain:

If the project is compiled at this point, the compiler may throw some errors. To avoid compiler errors, follow the below steps.

  • Add include directories as shown in the following image to avoid missing file errors for device.h and device_cache.h.
    • The include directory paths are shown below:
      • csp_apps_sam_d21_da1/apps/ac/ac_sleepwalk_singleshot/firmware/src/config/sam_d21_xpro
      • csp_apps_sam_d21_da1/apps/ac/ac_sleepwalk_singleshot/firmware/src/packs/ATSAMD21J18A_DFP
  • Comment the user row configuration bits #pragmas from the “initialization.c” file. This is because #pragmas are not recognized by the ARM GCC compiler.
  • Add or Edit the below files to make the project work with ARM GCC toolchain.
    • Add custom Linker file to the project.
    • Replace XC32 startup code with ARM GCC startup code. This can be done by adding “startup_gcc.c” file and excluding (or removing) “startup_xc32.c” file from project. Edit “libc_syscalls.c” file to compile with ARM GCC toolchain.
    • Add STDIO -> “gcc_monitor.c” file to make printf/scanf work properly. Exclude (or remove) the “xc32_monitor.c” file from the MPLAB Harmony v3 project.
      • This can be done as follows:
      • Go to config folder of Harmony v3 project config folder
      • Download the solution project from link reference_apps
      • From the downloaded solution project, copy the files from /apps/sam_d21_xpro/samd21_ac_sleepwalk_singleshot_gcc/src_gcc_toolchain and paste in the example application (downloaded from csp_apps_sam_d21_da1) folder apps/ac/ac_sleepwalk_singleshot/firmware/src/config/sam_d21_xpro
      • Paste the files “ATSAMD21J18A.ld”, “startup_gcc.c” in “sam_d21_xpro” folder and “gcc_monitor.c” file in “stdio” folder.
      • Right click Linker Files in MPLABX project -> Click Add Existing Item -> select corresponding recently added linker file and add to project. Below image is for reference.
      • Similarly, add “startup_gcc.c” file and “gcc_monitor.c” file to the project.
      • To Exclude a file from Project -> select the file -> Right Click -> select “Exclude file(s) from current configuration” or Remove file from the Project. The former option just exclude from the project and latter option will remove the file from project.
      • Replace the contents of “libc_syscalls.c” file in the project with the contents of “libc_syscalls.c” file in the zip. This file has definition of_sbrk() needed for ARM GCC compiler in addition to content what already present in it.
    • After completing the above steps, compile the project.
    • The project should compile successfully.

Running the Demo:

Results:

  • The console displays the message stating whether voltage at PA04 is lower or greater than the internal bandgap voltage (1.1 V)
  • LED0 toggles when comparison is done.

Conclusions:

This guide demonstrated building an MPLAB Harmony v3 peripheral Libraries (PLIBs) example with ARM GCC Toolchain. The same approach can be followed for any other Harmony v3 project.

               



Copyright © 2020 Microchip Technology.