Getting Started with USB on SAM MCUs Using MPLAB® Harmony v3: Step 4

Last modified by Microchip on 2023/11/09 09:08

Generate Code

Before generating code, save the MHC state by navigating to File > Save State in the main MHC menu. You may also click on the Save MHC State button.

Save MHC State

Figure 1: Save MHC State


Click on the Generate Code button or navigate to Generate > Generate Code from the menu bar to start generating code. Save if prompted.

Generate Code

Figure 2: Generate Code


Click on the Generate button in the Generate Project window, keeping the default settings.

Generate Project

Figure 3: Generate Project


As the code is being generated, MPLAB® Harmony Configurator (MHC) displays the progress.

Generating Project

Figure 4: Generating Project


Once this process completes, switch to the MPLAB X IDE window.

You may now examine the generated code through the Projects tab. MHC will include all the requisite MPLAB Harmony v3 Framework files and generate the configuration code dynamically based on your MHC selections. MHC will then automatically organize and add the generated code as files and folders to your 32-bit MPLAB Harmony 3 Project.

MHC generates a default template main file main.c and application files app_sensor.c/.h app_eeprom.c/.h app_usb.c/.h based on your MHC configuration. These will be used for the Sensor, EEPROM and USB Task state machines.

Generated Application Files

Figure 5: Generated Application Files

You will also notice that the Peripheral Library (PLIB) files are generated for the TC, TWIHS, AFEC, and PIO peripherals. The files for the USB Device Stack Middleware, I²C Drivers, and the Timer System Service are generated as well.

Generated Harmony v3 Framework Files

Figure 6: Generated Harmony v3 Framework Files


Build the code by clicking on the Clean and Build Main Project Main clean and build project icon button in the MPLAB X IDE and verify that the project builds successfully. At this point, you are ready to start implementing the application code.

Back to Top