MPLAB® Harmony is a flexible firmware development platform for PIC32 microcontrollers. This integrated software framework provides driver libraries and APIs that make it easier for you to use PIC32 peripherals (Timers, GPIO, UART, I2C, SPI, etc.). It also includes middleware libraries for USB (Host and Device), TCP/IP (Ethernet and WiFi®), Graphics, Bluetooth, and others.
This tutorial shows you how to use the MPLAB Harmony Configurator (MHC) to create a USB flash drive (a.k.a. thumb drive) audio player application running on the PIC32 Multimedia Expansion Board II (MEB II). The application will read WAV files from the flash drive (plugged into the MEB II board), decode them, and play them using the MEB II's audio CODEC. You will also learn how to use the MPLAB Harmony Graphics Composer (MHGC) to create a touch controlled display to control the USB flash drive player.
Two ways to use this tutorial:
- Create the project from scratch
- Use the provided source files and step-by-step instructions below.
- Use the solution project as an example
- Just build the solution project and download it to the MEB II Board to observe the expected behavior.
- Create an MPLAB X IDE Harmony project for a PIC32 microcontroller from scratch.
- Use the MPLAB Harmony Configurator (MHC) to configure and generate Harmony code.
- Use (MHC) to configure the audio CODEC on the PIC32 Multimedia Expansion Board II.
- Create new application states and variables for Harmony projects.
- Identify the proper place to add your own application code to the Harmony project.
- Demonstrate the use of Harmony peripheral libraries and drivers to control PIC32 peripherals (I2S, I2C, Timers etc.).
- Demonstrate the use of Harmony's USB and Graphics (middleware) libraries.
|Tool|| About|| Purchase|
It is not necessary to have an MPLAB Real ICE™ to program/debug the code. The PIC32MZ EF Starter Kit includes a PICkit™ on-board (PKOB) debugger. The PKOB debugger is connected to the host PC through the USB Mini-B connector on the PIC32MZ EF Starter Kit for programming/debugging (See Red Cable in the Hardware Setup)
Apart from the hardware tools listed above, the following items are required to play audio from a PC over the USB interface:
- Wired Stereo headphone.
- USB Type A male to micro-B male cable for USB audio speaker functionality.
- USB Type A male to mini-B male cable for programming/debugging.
Development Board User's Guide Files
This project has been verified to work with the following versions of software tools:
MPLAB X IDE v3.26, MPLAB® XC32 Compiler v1.40, MPLAB Harmony v1.08
Because we regularly update our tools, occasionally you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double check using the same versions that the project was tested with.
Archived versions of our tools can be found on the following Microchip websites:
MPLAB Harmony (see "Archived Downloads" tab)
MPLAB X IDE and XC32 Compiler (see "Downloads Archive" tab)
Note that multiple versions of all these tools can co-exist on the same computer.
| Windows|| Linux|| Mac OSX|
Integrated Development Environment
Integrated Software Framework
This lab application plays WAV audio files (sampling rate: 48 kHz, 16-bit data) stored in a flash drive. This is done by adding a CODEC driver and the USB Host Mass Storage Class (MSC) stack functionality to the project. The implementation is demonstrated by connecting a flash drive to the development board and then playing the WAV audio files saved on the flash drive.
|[Figure 1.1] APP_Tasks()|
This figure shows the application tasks. The APP_THUMB_DRIVE_AUDIO_Tasks handles USB flash drive and CODEC related states and events. The APP_DISPLAY_Tasks handles graphics related events.
|[Figure 1.2] APP_THUMB_DRIVE_AUDIO_Tasks()|
The Thumb drive Audio state machine first registers event handlers with the File System and USB Host layer and then enables the USB bus. Once the USB bus is enabled, the state machine waits for the device (thumb drive) to get attached. Once the thumb drive is attached (which is indicated by the File System - Mount event in the File System event handler) the state machine opens the audio CODEC driver, and registers a buffer event handler with it.
|[Figure 1.3] Audio Player State Machine|
The state machine then enters the audio running state. All folders on the flash drive are searched to create a table of existing WAV files. The audio player state machine then starts to run. The audio player states perform the task of reading the audio data from the opened WAV audio file, decoding the WAV raw data through audio decoder, and then passing the decoded buffer to the audio CODEC for playing. The audio player states also handle track change events and waiting for the current audio buffer completion event from the audio CODEC. This will be discussed in more detail in this step: Step 9: Review the application code
Lab Source Files and Solutions:
This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the labs per the following step-by-step instructions (see the "Procedure" section on this page).
The contents of this ZIP file need to be placed in this folder:
<Harmony install path>/apps/training/middleware/
(example Harmony install path = c:/microchip/harmony/v1_08)
If this is not done, the MPLAB X IDE will not be able to find all source files for the lab solution; the solution project will not build successfully.
- thumb_drive_player contains the lab folder thumb_drive_player_lab
- thumb_drive_player_lab contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
- dev_files contains application source files and other support files (if any) required to perform the lab (see "Procedure" section below).
- firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behavior.
All steps must be completed before you will be ready to build, download, and run the application.
- Step 1.1 – Create an MPLAB Harmony Project
- Step 1.2 – Select the Board Support Package (BSP)
- Step 1.3 – Verify Configuration Bits are Correct
- Step 1.4 – Verify and Change Oscillator Settings
- Step 1.5 – Use the Graphical Pin Manager to Verify I/O Pins
- Step 2.1 - Configure CODEC AK4953
- Step 2.2 - Configure I2C driver for CODEC
- Step 2.3 - Verify/Set the I/O Pins used by I2C module using the Graphical Pin Manager
- Step 2.4 - Configure I2S driver for CODEC
- Step 2.5 - Configure External Master Clock Input (MCKI) to the CODEC
- Step 2.6 - Configure/Verify DMA system service for allocating I2S transmit DMA channel
- Step 2.7 - Verify/Set the I/O Pins used by I2S module using the Graphical Pin Manager
- Step 6.1 - Rename the Screen Name
- Step 6.2 - Import Images and Fonts (Assets)
- Step 6.3 - Create Schemes (assign standard colors and fonts)
- Step 6.4 - Add Primitive Objects (rectangle, image, text)
- Step 6.5 - Add Widget Objects (list-box, buttons, slider)
- Step 6.6 - Configure the Graphics display and Graphics Touch Driver
- Step 6.7 - Enable Touchscreen Control using I2C
- Step 6.8 - Enable the Graphics Touch System Service
Table of Contents