Migrating a Graphics Application From a PIC32MZDA MCU to a SAM9X75 Hybrid MCU Curiosity Development Board
Introduction
This training module will teach you how to migrate a graphics application based on MPLAB® Harmony, and developed for high-performance LVDS WVGA LCD Display Module with maXTouch® technology display board using the Microchip Graphics Suite (MGS) for 200 MHz MIPS® core-based PIC32MZDA Curiosity Development Kit to an 800 MHz ARM926-EJS-based SAM9X75 Arm®-based MPU Curiosity Development Board.
Once the application has been fully migrated, 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, 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 given in the "Learn More" section.
Prerequisites
- Install MPLAB X IDE.
- Install MPLAB XC32/32++ Compiler.
Hardware
For this training, you will use the SAM9X75 Curiosity Development Board.
SAM9X75 Curiosity Development Board
See the "SAM9X75 Curiosity Development Board - Features" page.
Set up the SAM9X75 Curiosity Development Board as listed below to the host computer running MPLAB X IDE.
Jumpers
- Open Jumper J9 to disable NAND Flash boot.
- Open Jumper J10 to disable QSPI boot.
- Refer to Section 2.5 of the "SAM9X75 Curiosity User Guide" for more details about jumper settings.
SD Memory Cards
- Ensure no SD memory cards are plugged into the SD card (J14) connector.
Power
- Apply power as shown in the "Power Options" section of the "SAM9X75 Curiosity Development Board - Features" page.
Debug Communications
- The SAM9X75 Curiosity Development Board contains a 20-pin JTAG debug port. Connect a PICkit™ 5 debugger to the 20-pin JTAG debug port (J34) 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 “SAM9X75-Curiosity Development Board – Console Serial Communications” page.
Display
Hardware Setup
- Connect the ribbon cable from the display to the J28 connector of the SAM9X75 Curiosity Development Board. To learn more about the hardware connection between the LVDs display and the SAM9X75 Curiosity Development Board, refer to the "Hardware Guide for SAM9x75 Curiosity with 5" LVDS WVGA maXTouch Technology Display Module" page.
- Power up the board by connecting the Micro-USB cable to the USB-A port J2 on the SAM9X75 Curiosity Development Board.
- Connect the MPLAB PICkit 5 debugger to the 20-pin JTAG debug port (J34).
- Connect the FTDI cable to the serial debug port (J35) on the SAM9X75 Curiosity Development Board.
Porting an Application From the PIC32MZDA to the SAM9X75
In this tutorial, an automotive dashboard application of the PIC32MZDA Curiosity development kit is being migrated to the SAM9X75 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 traveled, and images for indicators like turn signals and other alerts. Follow the steps below to successfully migrate the application.
Generate the project graph for the SAM9X75 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 are changed from a default value.
Given this information, we will now set the project graph for the SAM9X75 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) and click Next.
In the Select Device dialog window, fill in or select the information below:
- Family: 32-bit MCUs and MPUs (PIC32C/SAM)
- Device: SAM9X75D2G
Then click Next.
In the Select Compiler pane, for Compiler Toolchains select XC32 Compiler, and click Next.
Populate the Project Location, Project Folder and Project Name fields. 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 choosing 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 tool bar). If MPLAB Harmony contents are not available in the MPLAB 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. 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 pane, click the add button to add Board Support Packages for SAM9X75 Curiosity BSP to the Project Graph.
From Device Resource > Graphics > Templates, add Legato Graphics w/ AC69T88A Display to Project Graph. You will be prompted to allow auto-connection and auto-activation of several components. Click on Yes for all of them except FreeRTOS®.
Choosing the Legato Graphics w/ AC69T88A 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.
Observe that the Graphics Canvas is embedded between XLCDC and Legato.
Select the canvas driver from the project graph, and under Graphics Canvas > Canvas Settings, enter "6" for the number of Canvas Objects. Set the following values:
- Canvas[0]
- Width: 1,600
- Height: 480
- Frame Buffer Allocation: Auto
- Canvas[1]
- Width: 300
- Height: 350
- Frame Buffer Allocation: Auto
Select the LE XLDC driver from the project graph, and on the configuration pane, under Clock Control > Enable Backlight PWM, ensure Canvas Mode was selected.
You can see that PA24 and PA25 are set to FLEXCOM6. Enable Pull Up for those pins. Ensure all the pins are configured as shown in the acompanying image:
Now click the Generate button to generate the code for the added peripherals.
The next step is to migrate graphics using Microchip Graphics Composer. Launch the Microchip Graphics Composer.
Then click Load an existing project.
Open the zipped PIC32MZDA Curiosity graphics design file from the downloaded MGS dashboard graphics project of PIC32MZDA as shown in the accompanying image.
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 click Save.
Now click Project > Memory Locations > DDR_PreProcess and modify the Address to 27000000 (external DDR address location to save assets in SAM9X75 Curiosity).
And then click the Generate Code button.
Now click the Generate button to generate the code for the migrated MGS graphics.
Modifications required in the source code and linker files.
Copy and add app.c, app.h, app_preprocess.c and app_scene1.c from the PIC32MZ DA project to the SAM9X75 Curiosity Development Board project as shown below.
Change the include path for gfx_canvas_api.h in app.c 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:
XLCDC_SetBacklightBrightness( brightness * 0xff / 100 );
In app.c, remove the PIC32MZDA platform-specific code. Delete the following lines in APP_Tasks():
TMR2_Start();
OCMP1_Enable();
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"
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 in the acompanying image:
This completes the migration of the PIC32MZDA graphics project to the SAM9X75 Curiosity Development Board.
Debugging the Dashboard Graphics Application on the Target:
To debug the project on MPLAB X IDE, make sure the board is powered and the external debugger is connected. Refer to the "Hardware Setup" section in this document for more details.
Right click on the project and click Properties. For Compiler Toolchain, select XC32. For Packs, expand SAM9X7_DFP and select 1.9.170 or latest. Click Apply.
Configure the debug interface of PICkit 5 as shown in the acompanying image:
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. Check the Execute this line after build box and then enter the below 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-complied version of the 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 SAM9X75 Curiosity, MPLAB X IDE can be used to run and debug the application. See the "SAM9X75 Curiosity – Configure and Build at91bootstrap for an MPLAB Harmony v3 Project with MPLAB X IDE" page.
Clean and build the project. You will 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 below steps:
Steps to Program the BIN File on SD Card
Take a microSD card formatted with FAT32 file system (see the "How to Format and Partition an SD Card Larger Than 32GB Using DiskPart in Windows® for MPU" page).
Copy the boot.bin files from this location to the microSD card using your PC.
Copy harmony.bin files (available in ./project_directory/Graphics_Application_Getting_Started.X/dist/default/production) to the microSD® card using your PC.
Insert the SD card to J14 on the SAM9X75 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 on the display connected with the SAM9X75 Curiosity Development Board.
Summary
In this training, an automotive dashboard application of the PIC32MZDA-Curiosity development kit was migrated to the SAM9X75 Curiosity Development Board using MGS under MPLAB X IDE.