Lab 3: SD Card Reader Support to Load Audio Files with MPLAB® Harmony v3

Last modified by Microchip on 2024/01/29 21:43

Warning: This tutorial uses the old Harmony configuration tool (MPLAB® Harmony Configurator (MHC)). New Harmony projects should use the MPLAB Code Configurator (MCC) instead.



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


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.

Note: 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 function

Lab Source Files and Solutions:

If you haven't already, download the lab source files and solutions.

Note: ​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:

Note: 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 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


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


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.

Back to Top