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 Wi-Fi®), Graphics, Bluetooth, and others.
This tutorial shows you how to use the MPLAB Harmony Configurator (MHC) to create a USB speaker application running on the PIC32 Multimedia Expansion Board II (MEB II). You will also learn how to use the MPLAB Harmony Graphics Composer (MHGC) to create a touch controlled display to control the USB speaker.
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 Framework libraries to use the USB middleware and Graphics Library.
|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
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 enables the MEB II Board to act as a USB speaker by playing audio data (sampling rate: 48kHz, 16-bit data), streamed by the USB host (typically a PC). This is done by adding a CODEC driver and the USB audio device library to the project.
|[Figure 1.1] APP_Tasks()|
Figure 1.1 shows the application tasks. The APP_USB_AUDIO_Tasks function handles USB audio application related states and events. The APP_DISPLAY_Tasks function manages volume changes and mute/un-mute requests from the GUI.
|[Figure 1.2] APP_USB_AUDIO_Tasks()|
The USB audio state machine (as shown in Figure 1.2) first opens the USB Device driver and registers a Device event handler to receive Device layer USB events. The state machine then opens the audio CODEC and registers a buffer event handler. It then waits for the USB host to configure the Device. After the Device is configured, the state machine enters an idle loop waiting for USB host events.
When the user opens an audio player application on the PC (USB host), the device receives (alternate) interface settings through the USB audio driver event handler. If the Device is capable of servicing the new settings, the state machine then requests the host to send a stream of audio data. Once the device receives the audio stream, it enters the process data state where it submits the received audio data to the CODEC driver for playing, and requests more data from the USB host. The cycle then repeats.
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, MPLAB X IDE will not be able to find all source files for the lab solution (see project in the firmware folder) and the solution project will not build successfully.
- usb_speaker contains the lab folder usb_speaker_lab
- usb_speaker_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 in the MPLAB X IDE
- Step 1.2 – With MHC, Select the Board Support Package (BSP)
- Step 1.3 – With MHC, Verify Configuration Bits are correct
- Step 1.4 – With MHC, Verify Oscillator Settings
- Step 1.5 – With MHC, Verify I/O pins using the Graphical Pin Manager
- 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 4.1 - Rename the Screen Name
- Step 4.2 - Import Images and Fonts (Assets)
- Step 4.3 - Create Schemes (assign standard colors and fonts)
- Step 4.4 - Add Primitive Objects (rectangle, image, text)
- Step 4.5 - Add Widget Objects (list-box, buttons, slider)
- Step 4.6 - Configure the Graphics display and Graphics Touch Driver
- Step 4.7 - Enable Touchscreen Control using I2C
- Step 4.8 - Enable the Graphics Touch System Service
Table of Contents