Lab 3: SD Card Reader Support to Load Audio Files with MPLAB® Harmony v3
Purpose
After completing this lab, 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 MPLAB® Harmony 3 Configurator (MHC).
Overview
This lab extends audio_player_lab2 by adding Secure Digital (SD) card reader functionality. The audio_player_lab3 application shows how to edit the contents of an SD card. The PIC32 Multimedia Expansion Board II (MEB 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 or 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 the Mass Storage Device (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) 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 an SD card reader allowing you to connect to the PC and load files (tone.txt for this lab) to the SD card.
App_Tasks()
Lab Source Files and Solutions:
If you haven't already, download the lab source files and solutions.
Procedure:
All steps must be completed before you will be ready to build, download, and run the application.
Lab Index
- Step 1 – Copy source files and rename project for Lab 3.
- 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.
Results
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.
Analysis
In this lab, you added USB MSD 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.
Conclusions
You added USB SD card reader support, thereby bringing your application one 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.