Step 1: Verify the MPLAB® Harmony "usb_speaker" demo application works without noise artifacts
Step 1.1: Create a new project based on the existing "usb_speaker" demo application
1
You probably don't want to modify any of the demo applications that come with the Harmony download (found in the <Harmony-Installation-Path>/apps folder). Make a copy of the "usb_speaker" demo application folder and paste it into a new folder.
- Create a new folder to hold your project
- Navigate to <Harmony-Installation-Path>/apps/audio
- Copy the usb_speaker folder
- Paste it into the new folder you just created
2
Start MPLAB® X IDE and open the usb_speaker project by selecting File > Open Project. Navigate to this folder to find the project:
<new folder you just created>/usb_speaker/firmware
When the project opens you will see two error tabs open in the output window.
The Configuration Loading Error window contains warning messages related to the project configuration. You can ignore this as you will resolve the problems in the following steps.
The Project Loading Error window refers to problems with the project itself. Some files in the project are included using relative paths to files in the Harmony framework. You likely broke these relative paths when you relocated the project. Fortunately, as you will see in the following steps, MHC will fix these broken paths for you.
Note:
The project you are modifying contains many project configurations. Each configuration includes different source files to support multiple hardware platforms. This lab will show you how to fix the include paths for the hardware you are using. Files associated with other (unused) project configurations will continue to produce error messages. You can ignore these or manually remove the offending files.
4
Change the project configuration to support the hardware used in this lab (the PIC32MZ EF Starter Kit mounted on the Multimedia Expansion Board II). Use the Set Project Configuration drop-down window in MPLAB X IDE to select the 'pic32mz_ef_sk_meb2' project configuration.
5
Verify the project is configured to use the correct device number and hardware tool.
From the main menu, select File > Project Properties (usb_speaker_rtos)
Be aware there are two different PIC32MZ Embedded Connectivity Starter Kits—one using a PIC32 with a crypto engine and one without. You may need to change the device number associated with the demo project to make it work for the starter kit you have.
- PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit
- Board part number: DM320007
- Device: PIC32MZ2048EFH144
- PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit with Crypto Engine
- Board part number: DM320007-C
- Device: PIC32MZ2048EFM144
7
Open MHC to re-generate the project's source files and reset the relative path between your project's folder and the Harmony framework folder.
From the main menu, select Tools > Embedded > MPLAB Harmony Configurator.
If you don't see 'MPLAB Harmony Configurator' under Embedded, you haven't installed the MHC plugin tool.
It's likely the new folder you created to place your project does not have the same relative path to the Harmony framework as the original folder it came from (the /apps/audio folder). If this is true, the MHC plugin tool will not be able to find a file it needs to start (<harmony installation path>/utilities/mhc/mhc.jar), so it will generate the following error message.
Click the Yes button, and browse to the folder containing the Harmony framework.
When MHC starts, it will ask if you want to open the configuration file used to save all previous MCH selections for the project. Click the Open button to do this.
8
Disable the Graphics stack. It's not needed for this tutorial, and MHC currently has a problem generating code for FreeRTOS projects requiring Graphics. This will be fixed in a future Harmony version.
In the MHC 'Options' tab, expand the Harmony Framework Configuration > Graphics Stack tree, and un-check the 'Use Graphics Stack?' box.
9
Every time you change the device or MHC settings, you need to re-generate the Harmony source files (this is an easy thing to forget). Click the Generate Code button (see image above). A Generate Project window will open to allow you to select a merging strategy. Make sure the 'Prompt Merge For All Differences' option is selected from the drop-down window and click Generate.
10
Merge new MHC generated code with existing code.
When MHC’s Generate Code button is clicked, MHC will modify and generate source files based on the options you selected in MHC. If MHC wants to change a file you previously modified, it will show you the code it generated (left window), and allow you to confirm if you want to add it to your current file (right window). It does this using a merge window (diff utility).
MHC wants to modify the sys_ports_static.c file to remove one line. This is the only change it wants to make. Click the Replace All arrow found between the windows at the top. After clicking the 'Replace All' arrow, click the Close button to accept the changes for each file.
Note: Clicking the 'Close' button saves the file as shown in the right window.
DO NOT click the 'Replace All' arrow for the system_config.h file. Instead, accept each change individually by clicking on the x's and arrows as shown in the following image. DO NOT accept the changes in the 'Application Instance 0 Configuration' section found near line 581. When you get to this section, keep this code (don't click on the x's or arrows), and save the file as it appears in the right window by clicking the Close button (top right window).
Accept all changes to the next four files (system_definitions.h, system_init.c, system_interrupt.c, system_tasks.c) by clicking the Replace All arrow found between the windows at the top. After clicking the Replace All arrow, click the Close button to accept the changes for each file.
Step 1.2: Build the project and program the device
1
2
Step 1.3: Detect and Set up the “USB Audio Speaker” on your PC
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 connector on the Multimedia Expansion Board II.
4
Next, open an audio player application on your PC. Let's take Windows Media Player application and Windows 7 for configuration and testing purposes. You should be able to achieve similar settings with your favorite media player too. Windows Media Player needs to be configured to use the Harmony USB Speaker. To set this option 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 Example),' and click OK.
5
Open your favorite track and hit the Play button on the player. You should be able to hear the selected audio track playing on your USB audio speaker.
Step 1.4: Verify the performance
You should not be able to hear any noise artifacts (static, distortion, clicks, or pops) while playing the selected audio track.
Now that you've verified the application works as expected, in the next step, you will break it by adding a new time-consuming task to it.
Table of Contents
|