Step 8: Debug your ApplicationCongratulations! You are ready to DEBUG 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.
You should be able to see the display now. The display screen should look the same as the one simulated in MHGC.
Wait for your PC’s operating system to detect the USB device and install necessary drivers. Open the windows Device Manger 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, Windows Media Player application is used. Next, Windows Media Player needs to be told to use the Harmony USB Speaker.
On 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: drop down 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 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/un-mute and increase/decrease volume of the audio speaker. If any of the device drivers (CODEC, I2C, 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.