SAMA7D65-Curiosity – Getting Started with MPLAB® Harmony v3 Development: RTC Application
Introduction
In this training, you will develop, configure, and build an MPLAB® Harmony v3 Software Framework application to run on the SAMA7D65-Curiosity Kit using MPLAB X Integrated Development Environment (IDE). This scenario is typical of project development, coding, building, and testing.
Once the application has been fully developed, the application is cleaned and built for production. The resulting binary image (harmony.bin) is written to Non-Volatile Memory (NVM), such as a Secure Digital (SD) memory card, embedded MultiMediaCard (eMMC), NAND, or NOR Flash memories. The harmony.bin binary image is read from NVM by the second-stage bootloader, at91bootstrap, which is also written to NVM. However, at 91boostrap must be configured and built for a given NVM. Instructions on how to do this are given in the "What’s Next?" section.
MPLAB Harmony v3 Application
This application demonstrates the control of RTC peripherals using Peripheral Libraries (PLIBs) with minimal external dependencies. This application prints the current date and time periodically and allows the user to set and print the date and time from a serial port.
Prerequisites
- Install MPLAB X IDE
- Install MPLAB XC32/32++ Compiler
Hardware
For this training, you will use the SAMA7D65-Curiosity Kit.
SAMA7D65-Curiosity Kit
See the "SAMA7D65-Curiosity Kit - Features" page.
Set up the SAMA7D65-Curiosity as listed below to the host computer running MPLAB X IDE.
Jumpers
- Open 1-2 of Jumper J36 to disable NAND Flash boot.
- Open 1-2 of Jumper J39 to disable QSPI Flash boot.
- Refer to the "Jumper Summary" section of the "SAMA7D65-Curiosity Kit - Features" page for more details.
SD Memory Cards
- Ensure no SD memory cards are plugged into the SD card (J10) connector.
Power
- Apply power as shown in the "Power Options" section of the "SAMA7D65-Curiosity Kit - Features" page.
Debug Communications
- The SAMA7D65-Curiosity contains a 20-pin JTAG Debug Port. Connect an MPLAB PICkit™ 5 debugger to the 20-pin JTAG Debug port (J38) 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 the "SAMA7D65-Curiosity – Console Serial Communications" page.
Developing a RTC Demo Application
Launch MPLAB X IDE from the main menu.
Create a New Project by clicking the New Project icon or by selecting File > New Project.
In the New Project window, under Projects choose Application Project(s) and click Next.
In the Select Device dialog window, fill in or select the information below:
- Family: Fill the configuration name as 32-bit MCUs and MPUs (PIC32C/SAM).
- Device: From the drop-down list, select SAMA7D65.
In the Select Compiler window, for Compiler Toolchains select XC32 (v4.60), and click Next.
Enter the Project Name, Project Location, and Project Folder. Click Finish.
This creates an empty project and sets this project as the main project. If there are other projects open in the Project Explorer window, set this project as the main project by right clicking on the project and selecting Set as Main Project.
Once the project is created, MCC will be automatically launched. (To launch MCC manually, from the main menu, click on Tools > Embedded > MPLAB Code Configurator or click the MCC button in the MPLAB X IDE toolbar). If MPLAB Harmony contents are not available in the framework path, it will launch the Content Manager Wizard.
In addition to the required packages (csp), download the optional packages, bsp and core, and then click Apply. The content download will take some time. Wait until all the contents are downloaded and then click Finish.
A project graph will be displayed. From the Device Resources window, click the add button to add Board Support Packages for SAM A7D65 Curiosity BSP to the Project Graph.
From the Device Resources window, expand Peripherals, and expand RTC to view the RTC list.
Click the add button to add RTC to the Project Graph.
RTC is added to the Project Graph window.
From the Device Resources window, expand FLEXCOM to view the list.
Click the add button to add FLEXCOM6 to the Project Graph.
FLEXCOM6 is added to the Project Graph window.
Add UART dependency by right-clicking on the UART button on FLEXCOM6 box and selecting Consumers > STDIO.
Save and then click Generate Code. This will generate code for all the Device Resources that have been added in the Project Graph.
Up to this point in the project creation process, you used MPLAB Code Configurator (MCC) to configure and generate code to initialize the device (SAMA7D65). Refer to the initialization.c file in project_directory/src/config to find that all the device resources added in the project graph were initialized. All that is left is for you to write the application code in the main.c and app.c file.
APIs used for this application are as follows:
- RTC_TimeSet
- RTC_TimeGet
- FLEXCOM6_USART_ReceiverIsReady
- FLEXCOM6_USART_ReadByte
Sample code can be found in main.c in project_directory/src folder of the downloaded project.
Right click on the project and select Properties. For Packs, select SAMA7D65_DFP > 1.4.54. For Compiler Toolchain, select XC32 and then click Apply.
By default, MPLAB X IDE only produces ELF and HEX format output files. To generate application output in binary format, a post build step needs to be added to the project properties. To do this, right-click on the project and select properties, select Building, and enable Execute this line after build. Then, enter the following command:
${MP_CC_DIR}/xc32-objcopy -O binary ${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.elf ${DISTDIR}/harmony.bin
Click on Apply and OK.
Clean and Build the project. You should see a message on the output console that the project was successfully built.
This completes the development of the RTC getting started application.
The harmony.bin binaries will be available in: ./project_directory/RTC_Application_Getting_Started.X/dist/default/production
Running the Pre-built Harmony Application from the SD Card
The pre-built application BIN file can be programmed by following these steps.
Steps to Program the BIN File to the SD Card
Take an SD card formatted with the FAT32 file system.
Copy the boot.bin and harmony.bin files from the project_directory/hex folder from the downloaded project to the SD card.
Insert the SD card to J10 on the SAMA7D65-Curiosity Kit.
Steps to Run the BIN File from SD Card
Press the START button and then press RESET button.
The following debug messages will be displayed on the console:
To set time, press any key and enter the command as $SETTIME HH:MM:SS (Ex: $SETTIME 11:25:35) and press Enter.
To set date, press any key and enter the command as $SETDATE WD:DD:MM:YYYY (Ex: $SETTDATE 00:01:01:2025) and press Enter. (MM: 00 - Jan, WD: 00 - Sunday)
To get time, press any key and enter the command as $GETTIME and press Enter.
Debugging Application Project on MPLAB® X IDE
Open project_directory/RTC_Application_Getting_Started.X in MPLAB X IDE.
Open the Project Properties using one of the following methods:
In the Projects pane, highlight RTC_Application_Getting_Started and click on the wrench icon in the RTC_Application_Getting_Started - Dashboard.
In the Projects pane, right-click on RTC_Application_Getting_Started and select Properties from the menu.
The Projects Properties – RTC_Application_Getting_Started dialog box opens.
Ensure SAMA7D65 is selected as hardware tool to program/debug the application.
In the Connected Hardware Tool drop-down menu, select the PICkit 5 debug probe and click the Apply button.
In the Categories pane, select PICkit 5.
In the Option categories drop down box, select Communications.
Change JTAG Speed to 1.00 MHz.
In the Categories pane, select Bootstrap.
Observe that Use bootstrap is selected and the pre-compiled version of the at91bootstrap.elf is selected. (The pre-complied at91bootstrap.elf can be found in the project_directory/hex folder in the downloaded project).
Click the Apply and OK buttons.
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 SAMA7D65-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 the Continue button. The application binary runs within the target.
Now the following debug messages will be displayed on the console:
To set time, press any key and enter the command as $SETTIME HH:MM:SS (Ex: $SETTIME 11:25:35) and press Enter.
To set date, press any key and enter the command as $SETDATE WD:DD:MM:YYYY (Ex: $SETTDATE 00:01:00:2025) and press Enter. (MM: 00 - Jan, WD: 00 - Sunday)
To get time, press any key and enter the command as $GETTIME and press Enter.
If you stop a debug session you must press the Reset button on the SAMA7D65-Curiosity to initiate the boot process before launching another debug session.
Summary
In this training, you developed, configured, and built an MPLAB Harmony v3 application example using MPLAB X IDE to run on the SAMA7D65-Curiosity Kit. Finally, you cleaned and built the application for production.
What’s Next?
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 image from NVM and writing to SDRAM. The following training topics show how this is done for NAND Flash, NOR Flash (QSPI), and an SD memory card.
For training topics on configuring and building at91bootstrap to load from Non-Volatile Memories (NVM), see:
- SAMA7D65-Curiosity – Configure and Build at91bootstrap for an MPLAB Harmony v3 Project with MPLAB X IDE
- SAMA7D65-Curiosity – Configure and Build at91bootstrap to Load an MPLAB Harmony v3 Application from NAND Flash Memory
- SAMA7D65-Curiosity – Configure and Build at91bootstrap to Load an MPLAB Harmony v3 Application from NOR Flash (QSPI) Memory
- SAMA7D65-Curiosity – Configure and Build at91bootstrap to Load an MPLAB Harmony v3 Application from SD Memory Card