USB Audio Speaker Tutorial: Step 8


< Back to Lab Start

Step 8: Debug your Application

Congratulations! You are ready to debugMain_Debug_Project.png the application!

1

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

2

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

3

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

4

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

image_98.png

5

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

image_99.png

6

Finally, you may put a breakpoint in theAPP_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.

image_100.png

7

Debug your application! Click theDebug Main Project iconMain_Debug_Project.png.

8

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

9

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

image_101.png

10

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.

11

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

image_102.png

Click on theDevices tab. Then selectSpeakers and click onProperties.

image_103.png

From theSelect the audio device dropdown box, selectSpeakers (Harmony USB Speaker) and clickOK.

image_104.png

12

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

13

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!

 Results

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.

 Analysis

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.

 Conclusions

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.