SAMA5D29-Curiosity – Getting Started with MPLAB® Harmony v3 Development: CSP Application: pio_led_on_off_interrupt
Contents
Introduction
In this training topic, you will download, configure, and build an MPLAB® Harmony v3 Software Framework application example using MPLAB X Integrated Development Environment (IDE) to run on the SAMA5D29-Curiosity Development Board in debug mode. This scenario is typical of project development steps of coding, building, and debugging.
While in Debug mode, the second-stage bootloader, at91bootstrap, is used by MPLAB X IDE to initialize Dynamic Random-Access Memory (DRAM) so that it can continue loading the MPLAB Harmony v3 project binary (harmony.bin). Once the project has been loaded onto the SAMA5D29-Curiosity, MPLAB X IDE can be used to run and debug the application.
Once a project has been fully developed, the application is cleaned and built for production. The application binary (harmony.bin) is loaded by at91bootstrap from Non-Volatile Memory (NVM), such as an SD memory card, e.MMC, NAND, NOR, and SQI™ Flash memories. Training topics on how to write binary files to NVM are given in the "Learn More" section.
MPLAB Harmony v3 Application
This Chip Support Package (CSP) Application example demonstrates the control of peripherals using Peripheral Libraries (PLIB) with minimal external dependencies.
This application uses the PIO Peripheral library to generate callback on switch press and release and drives the GPIO pin connected to the RGB LED to indicate the switch status. The RGB LED is turned ON when the switch is pressed and turned OFF when the switch is released.
Prerequisites
- MPLAB X IDE installed
- MPLAB XC32 Compiler installed
Hardware
For this training, you will use the SAMA5D29-Curiosity Development Board (P/N: EV07R15A) .
SAMA5D29-Curiosity Development Board
Setup the SAMA5D29-Curiosity as listed below to the host computer running MPLAB X IDE.
Jumpers
Set the jumpers to their default positions as shown in the “Jumper Summary” section of the “SAMA5D29-Curiosity - Features” page.
SD Memory Cards
Ensure no SD memory cards are plugged into SD Card slots (J6 or J7).
Power
- Apply power as shown in the “Power Options” section of the “SAMA5D29-Curiosity - Features” page.
Debug Communications
Connect a debug probe, such as the Microchip J-32 Debug Probe to the JTAG Connector (J12) and the host computer running MPLAB X IDE.
Console Serial Communications
To view the target console, connect the host computer running a terminal emulation program in accordance with “SAMA5D29-Curiosity – Console Serial Communications.”
Configure and Build a Project for Debugging
In this section, you will download, configure, and build a CSP Application example using the MPLAB X IDE to run on the SAMA5D29-Curiosity in Debug mode. This scenario is typical of the initial project development steps of coding, building, and debugging.
Normally, the MPLAB Harmony v3 Software Framework libraries are downloaded when a new MCC project is created in MPLAB X IDE. However, when working with an example application, such as this one, the MPLAB Harmony v3 Software Framework libraries are assumed to be preinstalled on the host computer. Therefore, if you do not have the MPLAB Harmony v3 Software Framework libraries preloaded, you must download or clone the CSP Application Library from the Microchip MPLAB Harmony v3 GitHub repository before opening the example application project. We will show you how in the following steps.
Download CSP Application Library
Create a Harmony3 Directory.
Create a directory named Harmony3. For a Windows operating system, it is typically located at C:\Users\<user>\Harmony3\
Download or clone csp_apps_sam_a5d2.
Download or clone csp_apps_sam_a5d2 library from the Microchip MPLAB Harmony 3 GitHub repository to the Harmony3 directory.
Open Project: pio_led_on_off_interrupt_sam_a5d2_curiosity.
From MPLAB X IDE, select File > Open project.
An Open Project window will open.
Locate the following project in the Harmony3 directory:
C:\Users\<user>\Harmony3\csp_apps_sam_a5d2\apps\pio\pio_led_on_off_interrupt\firmware\sam_a5d2_curiosity.X
Click on the Open Project button.
The pio_led_on_off_interrupt_sam_a5d2_curiosity project loads into MPLAB X IDE.
Configure Project Properties for debugging in MPLAB X IDE.
Open Project Properties.
Open the pio_led_on_off_interrupt_sam_a5d2_curiosity Project Properties using one of the following methods:
- In the Projects pane, highlight pio_led_on_off_interrupt_sam_a5d2_curiosity and click on the wrench icon in the pio_led_on_off_interrupt_sam_a5d2_curiosity - Dashboard.
- In the Projects pane, right-click on pio_led_on_off_interrupt_sam_a5d2_curiosity and select Properties from the menu.
The Projects Properties – pio_led_on_off_interrupt_sam_a5d2_curiosity dialog box opens.
Select the version of DFP and MPLAB XC32 Compiler you require for the application.
In the Connected Hardware Tool drop-down menu, select the connected debug probe.
Click on the Apply button. Observe under the Categories: Conf: [sam_a5d2_curiosity) that J-32 and Bootstrap are now listed.
Observe JTAG Speed (MHz) is set to 4.
In the Categories pane, select Bootstrap.
Observe that Use bootstrap is selected and the pre-compiled version of the at91bootstrap.elf is selected.
Configure the Harmony Content Path.
In this step, you will let MPLAB X IDE know the location (directory) of the MPLAB Harmony v3 Software Framework on your host computer.
Click on Apply and OK buttons.
Set Debug Reset and Debug startup options.
Configure the settings for:
- Debug Reset @ as Main
- Debug startup as Halt at Main
Power the SAMA5D29-Curiosity.
Power the SAMA5D29-Curiosity by connecting either:
- a USB-C cable to USB-A Port (J1) and host computer, or
- +5 VDC external power applied to connector J2.
Press the RESET push button (SW2).
This step places the first-stage bootloader into the SAM-BA Monitor mode. You can observe the RomBOOT message on the console.
Build the project.
Click on the Debug Project icon on the toolbar.
The project will build with debugging parameters, load the application binary to the SAMA5D29-Curiosity, and Halt at Main. Once the build is complete and the application binary is loaded into the target, the toolbar expands to show additional debugging icons.
You can view the second-stage bootloader (at91bootstrap) activity on the console.
Click on the Continue button. The application binary runs within the target.
Press the USER (SW1) push button and observe the RGB LED (D7) lights green. Release the USER push button and the RGB LED will turn off.
Continuing Development with MPLAB Harmony v3 Software Framework
With the project in Debug mode, you can now pause, insert additional breakpoints, and continue running the project. If you change the source code, you will need to reset the SAMA5D29-Curiosity prior to (re)building and loading the project to the target. Resetting places the MPU back into the bootloader mode.
For this example application, you only downloaded or cloned one MPLAB Harmony v3 library, CSP Applications for the SAMA5D29. There are several libraries required to perform full development. In this section, you will use MPLAB Code Configurator to download and manage these libraries.
MPLAB Code Configurator (MCC)
Start MCC by clicking on the MCC shield on the toolbar.
The MCC Content Manager Wizard will open. In the top half window is the Required Content.
Click on the Finish button at the bottom-right. The required content will be downloaded. Be patient, this will take a while.
If you received a Package Versions Used vs. Available dialog, perform the following steps:
In the Device Resources pane, click on the Content Manager button.
Observe the packages and versions that were called out in the dialog in Step 3.1 above. You can either:
- Individually select the latest version available for each package (in this example, the csp and dev_packs) and click the Apply button, or
- Click the Select Latest Version(s) button and click the Apply button. This will update all selected libraries to the latest version.
Changes will be applied and MCC will restart. You will see the Package Versions Used vs Available dialog again, this time showing the latest versions under the Local Packages column. Click the Continue button.
Click the Generate button.
MCC will generate new source code.
Download Packages for MPU Development
There are additional libraries required for MPU development. They are the Board Support Package (bsp) and Core (core).
- The BSP contains the defines (names and attributes) of the features (clock configuration, pins, switches, and LEDs) of a selected evaluation kit.
- The Core Package (core) contains device driver, system service, OSAL, and third-party software libraries.
Click on the Apply button.
The package versions will be downloaded and installed. MCC will restart.
The bsp and core libraries give you more resources for MPU development. However, there are a number of additional libraries available. Select and download them as needed using the same steps outlined above.
Click on the Generate button.
MCC will generate new source code.
Close MCC.
If displayed, merge all code.
Configure and Build a Project for Production
Once a project has been fully developed, the application is cleaned and built for production. The application binary (harmony.bin) is loaded from NVM, such as SD memory card, eMMC, NAND, and NOR Flash memories, by the second-stage bootloader, at91bootstrap.
Clean and Build the Project
Observe the location of the production binary. Take note of this location as it contains the harmony.bin binary that you will write into NVM.
C:\Users\<user>\Harmony3\csp_apps_sam_a5d2\apps\pio\pio_led_on_off_interrupt\firmware\sam_a5d2_curiosity.X\dist\sam_a5d2_curiosity\production\harmony.bin
Observe the DDRAM Address that harmony.bin is to be loaded to by at91bootstrap. This is found in the Linker Files, ddram.ld. Take note of this value as it is required for configuring at91bootstrap to load harmony.bin from NVM.
Summary
In this training topic, you downloaded, configured, and built an MPLAB Harmony v3 application example using the MPLAB X IDE to run on the SAMA5D29-Curiosity Development Board in debug mode. You cleaned and built the application for production and now it’s ready for writing into NVM.
Learn More
Once an MPLAB Harmony v3 application (harmony.bin) has been developed and built for production, the next step is to configure and build the second-stage bootloader, at91bootstrap, for reading the harmony.bin binary from NVM and writing to SDRAM. The following training topics show how this is done for SQI™ Flash memory and SD memory card.
- SAMA5D29-Curiosity – Configure and Build at91bootstrap to Load a MPLAB® Harmony v3 Application from SQI Flash Memory
- SAMA5D29-Curiosity – Writing MPLAB Harmony v3 Application and at91bootstrap to SQI Flash Memory using SAM-BA ISP
- SAMA5D29-Curiosity – Configure and Build at91bootstrap to Load a MPLAB® Harmony v3 Application from SD Memory Card
- SAMA5D29-Curiosity – Copy MPLAB Harmony v3 Application and at91bootstrap to SD Memory Card