USB Audio Speaker Tutorial: Step 8

< Back to Lab Start

Step 8: Debug your Application

Congratulations! You are ready to debug Main_Debug_Project.png the application!


Connect a USB cable from the micro USB connector (J4) on the PIC32MZEF Starter Kit Board to the PC.


Connect a headphone to the HP Out connecter on the Multimedia Expansion Board II.


Before you start the debugger, you may want to set a breakpoint in the application file app_usb_audio_task.c to verify that important stages of the application are executed successfully.


Put a breakpoint in the APP_USB_AUDIO_STATE_INIT state which will indicate that the USB driver is opened successfully.



Next, put a breakpoint in APP_USB_AUDIO_STATE_WAIT_FOR_CONFIGURATION state which will indicate that the USB host has configured the device successfully.



Finally, you may put a breakpoint in the APP_USB_AUDIO_STATE_IDLE state which indicates that audio CODEC is configured successfully and the application is now ready to receive an audio data stream and audio control commands.



Debug your application! Click the Debug Main Project icon Main_Debug_Project.png.


You should be able to see the display now. The display screen should look the same as the one simulated in MPLAB Harmony Graphics Configurator (MHGC).


Wait for your PC’s operating system to detect the USB device and install necessary drivers. Open the windows Device Manager and expand the Sound, video, and game controllers list. You should be able to see Harmony USB Speaker listed here.



Verify that the application goes through the breakpoints previously set and that the USB task is in APP_USB_AUDIO_STATE_IDLE which means that the USB device has been opened successfully and the USB host has configured the device.


Next, open an audio player application on your PC. For this lab, the Windows Media Player application is used. Next, Windows Media Player needs to be told to use the Harmony USB Speaker.
On the Windows Media Player application, go to Organize > Options.


Click on the Devices tab. Then select Speakers and click on Properties.


From the Select the audio device dropdown box, select Speakers (Harmony USB Speaker) and click OK.



At this point, remove all break points. Reset and run the application.


Open your favorite track and hit the play button on the player and you should be able to hear the audio track getting played on your USB audio speaker!


You should be able to play audio tracks on PC with the MEB II board acting as a (USB) speaker. The users should also be able to mute/unmute and increase/decrease the volume of the audio speaker. If any of the device drivers (CODEC, I²C, I2S) or the USB library are not configured correctly, you may hear distorted audio.


USB speaker functionality was added by configuring the CODEC and USB Library provided by MPLAB Harmony (using MHC) for USB Device mode operation and USB Audio class. The CODEC was configured for a 48000 Hz sampling rate and 16-bit data operation. The number of USB interfaces was configured to two: one for transferring audio controls (Endpoint 0) and one for transferring the audio data stream (Endpoint 1).

All the USB descriptors were populated and set to appropriate values by the MHC. A basic GUI using MHGC was also created to allow for volume and mute controls. At the application level, a USB task (state machine) was added that handled USB related events and streaming of audio data received from the USB host (PC) to the CODEC. The display task handled volume control events. After a successful enumeration by the USB host, when audio is played on the USB host (PC), the USB device receives alternate settings on USB interface 1. The USB device then requested audio data from the USB host.


This lab demonstrated the use of the Harmony USB device library for adding audio support to your application. It acts as an audio speaker with USB as the interface medium for the audio stream. It also showed how easily and quickly you can add USB, audio and graphics support to your application using MHC and MHGC. As a next step, you may want to configure the USB library in host mode to play audio files from 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.