Lab3: SD Card Reader Support to Load Audio Files with Harmony v2

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 the MPLAB® Harmony Configurator (MHC).

Overview:

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 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 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 an 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.

App_Tasks()
image_1.png

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

As the tools are regularly updated, there may be occasional issues while using newer versions. If that is the case, we recommend using the same version as specified in the project.

The archived versions of our tools can be found below:
MPLAB Harmony
MPLAB X IDE and XC32 Compiler

Note that multiple versions of all these tools can co-exist on the same computer.

Procedure:

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.

Lab Index

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

 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 the MHC. You also demonstrated how the 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.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.