Step 1.1: Create an MPLAB® Harmony Project
1
Create a folder under the Harmony installation to place this lab. Navigate to
<Harmony-Installation-Path>/apps and create the folder structure, training/middleware.
Extract the ZIP file you downloaded to the training/middleware/ folder. A description of the files and folders found in this ZIP file can be found here.
2
Navigate to <Harmony-Installation-Path>/apps/training/middleware and create the folder structure, dev/thumb_drive_player. The lab will be developed in the dev/thumb_drive_player folder. MPLAB® X IDE will create the thumb_drive_player_lab sub-folder inside dev/thumb_drive_player.
3
Start MPLAB X and create a new project by selecting File > New Project.
4
In the Categories pane of the New Project dialog, select Microchip Embedded.
6
Specify the following in the New Project dialog (see below):
- Harmony Path : <Harmony install path>
- Project Location : <Harmony install path>/
apps/training/middleware/dev/thumb_drive_player - Enter Project Name : thumb_drive_player_lab
- Configuration Name : pic32mz_ef_sk_meb2 (this is optional)
- Target Device : PIC32MZ2048EFH144
7
After clicking the Finish button, the project will be created and opened. You will see the MPLAB Harmony Configurator (MHC) window along with the integrated Harmony Help file.
If you close the MHC window, you can re-open it by clicking on Tools > Embedded > MPLAB Harmony Configurator.
Step 1.2: Select the Board Support Package (BSP)
1
Click on the Options tab in the MPLAB® Harmony Configurator main window to select and configure the Harmony Framework in a graphical tree-based format.
2
Expand the BSP Configuration tree, and then select PIC32MZ EF Starter Kit w\ Multimedia Expansion Board (MEB) II
If a Board Support Package (BSP) exists for your development board you will want to use it. Choosing a BSP lets the MPLAB Harmony Configurator (MHC) know about the hardware you will use for the project.
By selecting a BSP, MHC can automatically control the following settings for you:
- PIC32 core configuration (Watchdog Timer and debugger channel)
- PIC32 oscillator configuration (including external clock/crystal)
- PIC32 I/O Port pin connections to LEDs and switches
In addition to configuring hardware options for you, the BSP comes with a small group of library functions that allow you to more easily interface with LEDs and switches. In this lab, you will observe the selections the BSP makes for you. This will show you how to make these selections manually in case a BSP does not exist for the board you want to use.
Step 1.3: Verify Configuration Bits are Correct
1
In the central window under the MPLAB Harmony Configurator tab, click on the Options sub-tab, to view the MPLAB Harmony & Application Configuration tree selections.
2
Expand the Device & Project Configuration tree then expand the PIC32MZ2048EFH144 Device Configuration.
The BSP you selected has properly configured these selections for you. This step shows you how to make changes to these selections if needed.
- DEVCFG3 and DEVCFG2 – No change
- DEVCFG1 – No change, but verify the Watchdog Timer Enable (FWDTEN) is OFF
- DEVCFG0 – No change
In case you are wondering where these cryptic selection names come from, they correspond with the PIC32 core configuration registers and bit names. Please see the device datasheet for details.
Before moving to the next step, you may want to collapse the Device & Project Configuration tree.
Step 1.4: Verify and Change Oscillator Settings
Select the Clock Diagram tab to display the Clock Configurator window.
1
Verify the following clock parameters:
- POSCMOD set to EC
- FNOSC set to SPLL
- FPLLIDIV set to DIV_3
- FPLLMULT set to MUL_50
- FPLLODIV set to DIV_2
Experiment with other clock settings. Did you notice how some selections produce red values? These indicate a bad clock configuration. If you mouse over them, a pop-up window will tell you what the problem is.
The PIC32 is connected to a 24 MHz external clock input. You are not using the internal PIC32 oscillator.
When you change the configured clocks away from the default values on the graphical interface, they are reflected as a shaded field in the Options Configuration Bits. Since the BSP selected the default values, there should be no shading. To illustrate this, notice when the FPLL DIV is changed to a Divide By 1 instead of 3 in the CLOCK DIAGRAM graphical interface, the Options tab will reflect the changes in DEVCFG1 with Shading. You can configure the clocks using the tree selections, but it is much easier to do graphically!
The BSP has already configured the Phase Locked Loop (PLL) using the selections for the PIC32MZ EF Starter kit \w Multimedia Expansion Board II. For custom boards without a BSP, you can use the PLL’s Auto Calculate feature to determine and set the PLL to multiply and divide values (FPLLIDIV, FPLLMULT, and FPLLODIV). You can see how this works by going back to the Clock Configurator window (Clock Diagram tab).
2
Change the PIC32 clock frequency to 198 MHz.
This development board can run at a maximum frequency of 200 MHz (selected by default by the BSP). You are using the audio CODEC on the board, so you need to configure the system frequency to 198 MHz. The reason for this specific frequency is described in the "Configure Audio CODEC" step.
- In the MHC Clock Diagram tab, find the System PLL block and select Auto Calculate
- Change the Desired System Frequency from 200 MHz to 198 MHz.
- Select Apply
Verify the output to the PLL is now set to 198 MHz.
Step 1.5: Use the Graphical Pin Manager to Verify I/O Pins
2
Verify the BSP (selected in a previous step above) has properly configured the PIC32 pins based on the external devices connected to them. You will be using the Audio CODEC AK4953, LCD Display, LEDs, and Switches. Select the Pin Table tab in the MHC output pane (see the following screenshot).
If this window is minimized, it can be found on the bottom left part of the MPLAB X IDE. Click on it to maximize it.
- Notice that PINs 43, 44, 45, 67, and 84 have LED_n selected on them.
- Notice that PINs 59, 60, 61, and 22 have Switch_n selected on them.
- Notice that the PIN 46 has Power down enable/disable for the CODEC AK4953 selected on it.
- Notice that the PINs 26, 35, 39, 57, 117, and 133 are selected to interface with the Graphics LCD.