Migrating a Graphics Application from a PIC32MZDA MCU to a SAM9X60 Hybrid MCU Curiosity Development Board
Introduction
This training module will teach how to migrate an MPLAB® Harmony-based graphics application developed for a high-performance WVGA LCD Display Module with maXTouch® technology display board using the Microchip Graphics Suite (MGS) for a 200MHz MIPS® core-based PIC32MZDA Curiosity Development Kit to a 600MHz ARM926-EJS-based SAM9X60 Arm®-based MPU Curiosity Development Board.
Once the application has been fully migrated, it 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, 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, at91boostrap must be configured and built for a given NVM. Instructions on how to do this are provided in the "Learn More" section.
Prerequisites
- Install MPLAB X IDE
- Install MPLAB XC32/32++ Compiler
Hardware
SAM9X60 Curiosity Development Board
See the "SAM9X60 -Curiosity Development Board - Features" page.
Set up the SAM9X60 Curiosity Development Board as listed below to the host computer running MPLAB X IDE.
Jumpers
Open 1-2 of Jumper J4 to Disable NAND Flash boot.
Refer to the "Jumper Summary" section of the " SAM9X60 - Curiosity Development Board - Features" page for more details
SD Memory Cards
Ensure no SD memory cards are plugged into the SD card (J5) connector.
Power
Apply power as shown in "Power Options" section of the "SAM9X60 Curiosity Development Board - Features" page.
Debug Communications
The SAM9X60 Curiosity Development Board contains a 20-pin JTAG debug port. Connect an MPLAB® PICkit™ 5 debugger to the 20-pin JTAG debug port (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 the “SAM9X60 - Curiosity Development Board – Console Serial Communications” page.
Hardware Setup
- Connect the ribbon cable from the display to the J13 connector of the SAM9X60 Curiosity Development Board.
- Power up the board by connecting the USB cable to the USB port J1 on the SAM9X60 Curiosity Development Board.
- Connect the MPLAB PICkit 5 debugger to the 20-pin JTAG Debug port (J12) .
- Connect the FTDI cable to the Serial Debug Port (J11) on the SAM9X60 Curiosity Development Board.
Porting an Application From One PIC32MZDA to SAM9X60
In this tutorial, an automotive dashboard application of the PIC32MZDA Curiosity development kit is being migrated to the SAM9X60 Curiosity Development Board. This dashboard application presents a vehicle dashboard User Interface (UI). It has a gauge to show the engine RPM (tachometer), dynamic text to show speed and distance travelled, and images for indicators like turn signals and other alerts. Follow the steps below to migrate the application successfully.
The first step is to clone the PIC32MZDA Curiosity development Kit’s graphics application from GitHub.
Before generating the project graph for the SAM9X60 Curiosity Development Board, let us take a look at the project graph of the dashboard app for the PIC32MZ DA. To open the project graph of PIC32MZDA , open the dashboard project in MPLAB X IDE, set it as the main project, and launch MCC.
Now start observing the project graph for the components used in the project graph. The following components are used:
The BSP for PIC32MZ DA.
Legato Graphics w/ PDA TM5000 Display template – This automatically activates the rest of the components and connects them.
Graphics Canvas is used between the GLCD driver and Legato.
In the GLCD driver configuration, the canvas mode option is checked. Observe that in graphics canvas configuration, the number of canvas objects is set to 6, and for Canvas[0] and Canvas[1], the width and height of the object is changed from a default value.
Given this information, let us now set the project graph for the SAM9X60 Curiosity Development Board project. To do this, first 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). Then, click Next.
In the Select Device dialog, fill in or select the information below:
- Family: 32-bit MCUs and MPUs (PIC32C/SAM)
- Device: SAM9X60
In the Select Compiler pane, for Compiler Toolchains, select XC32 Compiler and click Next.
Enter Project Location, Project Folder, and Project Name. 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 main project by right-clicking on the project and choosing Set as Main Project.
Once the project is created, MCC will be automatically launched. (To launch the MCC manually, from 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 Harmony framework path, then it will launch Content Manger Wizard.
In addition to the required packages (csp), download the optional packages bsp, core, gfx, and then click Apply. Content download will take some time. Wait until all the contents are downloaded. Then click Finish.
A project graph will be displayed. From the Device Resources pane, click the add button to add Board Support Packages for SAM9X60 Curiosity BSP to the Project Graph.
From the Device Resources pane, add Graphics > Templates > Legato Graphics w/PDA TM5000 Display to Project Graph. You will be prompted to allow auto-connection and auto-activation of several components. Click on Yes for all EXCEPT FreeRTOS.
Choosing the Legato Graphics w/PDA TM5000 Display template automatically populates the rest of the project components. This can be seen in the way the project graph is set up and connected.
Since the PIC32MZDA application uses the Graphics Canvas component between the XLCDC and Legato drivers, first disconnect the direct link between XLCDC and Legato.
Click on the green diamond for LE Display Driver for LE XLCDC Driver and click on Disconnect. The diamond will turn yellow after the disconnection.
Right click on the yellow diamond on the LE LCDC driver, and for Consumers, select Graphics Canvas. Now observe that the Graphics Canvas component appears on the project graph.
Right click on the yellow diamond on the Graphics Canvas driver, and for Consumers, select Legato. The Legato and Graphics Canvas components are automatically connected.
Now the Project Graph looks like the acompanying image:
Select the canvas driver from the project graph, and on the configuration window. Use the image below for the following adjustments:
- Canvas Objects: 6
- Canvas[0]
- Width: 1,600
- Height: 480
- Frame Buffer Allocation: Auto
- Canvas[1]
- Width: 300
- Height: 350
- Frame Buffer Allocation: Auto
- Canvas[2]
- Frame Buffer Allocation: Auto
- Canvas[3]
- Frame Buffer Allocation: Auto
- Canvas[4]
- Frame Buffer Allocation: Auto
- Check the boxes for Canvas Mode and Use GPU for Blits?
Now click the Generate button to generate the code for the added peripherals.
The next step is to migrate graphics using Microchip Graphics Composer. Before we start, launch the Microchip Graphics Composer.
Then click Load an existing project.
Open the zipped graphics design file of PIC32MZDA Curiosity from the downloaded MGS dashboard graphics project of PIC32MZDA as shown below.
Now save the design files by clicking on File from the main menu and selecting Save As. Provide a Filename with <configuration_name>_design (e.g., default_design.zip) and save it in the default folder so that the next time MGC is launched, the design file is automatically opened. Then, click Save.
Click Project > Memory Locations > DDR_PreProcess and modify the Address to 27000000. (External DDR address location to save assets in SAM9X60 Curiosity).
Then click Generate Code.
Click the Generate button to generate the code for the migrated MGS graphics.
Modifications required in the source code and linker files include:
Copy and add app.c, app.h,app_preprocess.c and app_scene1.c from the PIC32MZ DA project to the SAM9X60 Curiosity Development Board project as shown below.
In app.c, change the include path for gfx_canvas_api.h from:
#include "config/glcd_rgba8888_mxt_mzda_intddr_cu_wvga/gfx/canvas/gfx_canvas_api.h"
to:
#include "config/default/gfx/canvas/gfx_canvas_api.h"
In app.c, change the following line of code in Backlight_TimerCallback() from:
OCMP1_CompareSecondaryValueSet( (TMR_PERIOD * brightness)/100);
to:
LCDC_BrightnessSet ( brightness * 0xff / 100 );
In app_scene1.c, remove the following #include for GLCD driver (the GLCD driver is for PIC32MZDA):
#include "gfx/driver/controller/glcd/plib_glcd.h"
#include "gfx/driver/controller/glcd/drv_gfx_glcd.h"
Copy and add app.c, app.h, app_preprocess.c and app_scene1.c from the PIC32MZ DA project to the SAM9X60 Curiosity development board project.
In the plib_flexcom6_twi_master.c file, add the following line of code to enable filter in flexcom6_TWI_Initialize():
In the linker file, add a dedicated section for assets_preprocess (DDR address should be the same as that of the address used in step 29) as shown below:
This completes the migration of the PIC32MZDA graphics project to the SAM9X60 Curiosity Development Board.
Debugging the Dashboard Graphics Application on the Target:
To debug the project on MPLAB X IDE, make sure the board and is powered and the external debugger is connected. Refer to the "Hardware Setup" section in this page for more details.
Right-click on the project and click Properties.
- For Compiler Toolchain select XC32.
- For Packs expand SAM9X6_DFP > 1.11.127 or latest
Then, click Apply.
Configure the debug interface of PICkit 5 as shown below:
By default, MPLAB X IDE only generates 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 > Building, and then check the Execute this line after build box. Then, enter the following command:
${MP_CC_DIR}/xc32-objcopy -O binary ${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.elf ${DISTDIR}/harmony.bin
In the Categories pane, select Bootstrap.
Observe that Use bootstrap is selected and the pre-compiled version at91bootstrap.elf is selected.
While in Debug mode, the second-stage bootloader, at91bootstrap, is used by MPLAB X IDE to initialize DRAM so that it can continue loading the MPLAB Harmony v3 project binary (harmony.bin).
Once the project has been loaded onto the SAM9X60 Curiosity, MPLAB X IDE can be used to run and debug the application. See the "SAM9X60 Curiosity Development Board - Configuring and Building at91bootstrap for an MPLAB® Harmony 3 Project Using MPLAB® X IDE" page.
Clean and Build the project. The user should see a message on the output console that the project was successfully built. This completes the building of the MPLAB Harmony application.
The harmony.bin binaries will be available at ./project_directory/Graphics_Application_Getting_Started.X/dist/default/production.
Now start debugging the project by step in, step out, halt or run.
Now observe the MGS dashboard graphics application using Microchip Graphics Composer on the display.
Running the Pre-Built MPLAB Harmony Application From the SD Card:
The pre-built application bin file can be programmed by following the steps below.
Steps to Program the BIN File on the SD Card
Take a microSD Card formatted with the FAT32 file system. See the "How to Format and Partition an SD Card Larger Than 32GB Using DiskPart in Windows® for MPU" page.
Copy harmony.bin files (available in the ./project_directory/Graphics_Application_Getting_Started.X/dist/default/production folder) to the microSD card using your PC.
Insert the SD card into J3 on the SAM9X60 Curiosity Development Board.
Steps to Run the BIN File From the SD Card
Press the reset button.
It will display the automotive dashboard graphics application connected with the SAM9X60 Curiosity Development Board.
Summary
In this training, an automotive dashboard application of the PIC32MZDA Curiosity development kit is being migrated to the SAM9X60 Curiosity Development Board using MGS under MPLAB X IDE.
Learn More
- Hybrid Microcontrollers (MCUs)
- Key Benefits of MCU to Hybrid MCU Migration: Performance, Scalability, Advanced Features
- Migrating a Graphics Application from PIC32MZDA MCU to a SAM9X60 Hybrid MCU Curiosity Development Board
- Migrating a Graphics Application from PIC32MZDA MCU to a SAM9X75 Hybrid MCU Curiosity Development Board
- Getting Started with Graphics on SAM9X60 Curiosity Development Board