After completing Lab 3, you will have an understanding of how to configure and add the Harmony Universal Serial Bus (USB) Library for Mass Storage Device (MSD) class using the MPLAB® Harmony Configurator (MHC).
This lab extends audio_player_lab2 by adding SD (Secure Digital) card reader functionality. The audio_player_lab3 application shows how to edit contents of an SD card. The PIC32 Multimedia Expansion Board II is connected to a USB Host (typically a PC) and after a successful enumeration, the SD card is presented as a mass storage drive on the PC allowing you to add/delete contents.
You will add a new task to handle the USB device events for the SD card reader. Apart from registering a USB Device layer events handler, the application need not intervene in the functionality of MSD Function driver since the MSD function driver does not provide any application callable functions.
You will also add a task to handle button (switch S1 on the MEB II Board) press events. Pressing switch S1 will allow you to switch between the SD card player mode and the SD card reader mode. By default, the SD card player mode is selected and the application will read and play the tone.txt file (if present) on the SD card. When switch S1 is pressed, the device will act as a SD card reader allowing you to connect to the PC and load files (tone.txt for this lab) to the SD card.
For Lab3, you will be able to play audio data saved in a tone.txt file by loading it through the USB interface.
For subsequent Labs, you will be able to play WAV files by loading them to the SD card using the USB interface.
Lab Source Files and Solutions:
If you haven't already downloaded all source files for the SD card Audio Player labs:
Download the lab source files and solutions >
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.
This lab builds off the work you performed in the previous lab. If you did not perform SD card Audio Player Lab2, please start Lab3 using the Lab2 solution project (found under the firmware folder). Verify it works as expected before continuing with this lab.
All steps must be completed before you will be ready to build, download, and run the application.
- Step 1 – Copy source files and rename project for Lab3.
- Step 2 – With MHC, Configure USB Library.
- Step 3 – Generate Harmony code.
- Step 4 – Include application specific source files, add required code and build the project.
- Step 5 – Review the application code.
- Step 6 – Debug your application.
Step 1: Copy source files and rename project for Lab3
Step 2: Configure the USB Library
Step 3: Generate Harmony code
Step 4: Include application specific source files, add required code and build the project
Step5: Review the Application code
Step 6: Debug your Application
You should be able to view and edit the contents of the micro SD card by connecting the device to the USB host (PC). You will also be able to switch between the audio player functionality and the SD card reader functionality through the press of a button.
In this Lab, you added USB Mass Storage Device support using MHC. You also demonstrated how MHC is capable of handling multiple clients that access the same SD card media. At the application layer, you added a new task (state machine) to handle a button press event to allow the users to switch between the audio player and SD card reader modes.
You added USB SD card reader support, thereby taking your application a step closer to a full fledged audio player. The lab demonstrates how easily you can add USB MSD class functionality to your applications. It also shows that there is little to no application overhead when it comes to handling MSD class events, as all these events are handled by the USB Library. Going forward, you may want to add USB Host functionality to the device to read a file (e.g., tone.txt or audio files) stored on a thumb-drive.
Table of Contents