Lab3: SD Card Reader Support to Load Audio Files with 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.

For Lab 3, 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, download the lab source files and solutions.

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v5.25
MPLAB XC32 Compiler v2.30
MPLAB Harmony v3.3.2
DEV_PACKS v3.5.0
CORE v3.5.0
CSP v3.5.0
BSP v3.5.0
AUDIO v3.4.0
USB v3.3.0

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: 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 Lab 2, please start Lab 3 using the Lab 2 solution project (found under the firmware folder). Verify that 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 Lab 3

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

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