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

Step 2.1 - Configure TIME System Service

  • When you launch MCC for the first time, it displays a prompt asking for the mode in which you would like to use MCC.
    • Standalone mode (as a separate window)
    • Native mode (as an embedded window in MPLAB X)
  • Standalone mode is the default mode.
  • MCC will launch in the operating mode selected the first time, every time you launch MCC.

For this lab, MCC is configured to operate in Standalone mode.

1

Switch to the MCC window and look for the TIME System Service module. You can add this by double clicking the module name under Resource Management[MCC] > Device Resources > Harmony > System Services > TIME.

add_time_component.png
Figure 1: Add TIME System Service Component

2

Accept the Core module auto-activation prompt. Since we will not use FreeRTOS™ for our application, defer enabling this component for now. Once you are done, the module should be visible in the Project Graph pane.

accept_core_auto_activation.png
Figure 2: Accept Core module auto-activation
deny_freertos_auto_activation.png
Figure 3: Defer FreeRTOS auto-activation
time_project_grapg_just_added.png
Figure 4: Project Graph after adding TIME System Service

3

Add the TC0 Peripheral Library as the timekeeper for the TIME System Service, which will set itself up automatically once this dependency is added. No further configuration is required for our use case of generating a periodic interrupt every second. You can add this by right-clicking on the dependency icon on the module.

The dependency icon on the module is highlighted in red when a direct dependency (i.e., required for a module to function) is not satisfied. Harmony 3 provides you the freedom to pick a module of your choice from a list of compatible modules to satisfy this dependency.

TC stands for Timer Counter and is a peripheral is available in the SAM and UC3 family of devices.

add_tc_plib.png
Figure 5: Add TC0 Peripheral Library
time_project_graph_final.png
Figure 6: Project Graph with TIME System Service successfully configured.

Step 2.2 - Configure I²C Driver

1

Add the I²C Driver module. You can add this by double clicking the module name under Resource Management[MCC] > Device Resources > Harmony > Drivers > I2C.

add_i2c_module.png
Figure 7: Add I²C Driver Component
project_graph_after_adding_i2c.png
Figure 8: Project Graph after adding I²C Driver

2

Add the TWIHS0 Peripheral Library to satisfy the I²C Driver's direct dependency.

TWIHS stands for Two Wire Interface High Speed and it's the I²C peripheral available in the SAME70/S70/V70/V71 family of devices.

add_i2c_plib.png
Figure 9: Add TWIHS0 Peripheral Library
i2c_project_graph_final.png
Figure 10: Project Graph after adding Peripheral Library

3

Verify the TWIHS0 clock settings by clicking on the module in the Project Graph. It should be set to 400 kHz.

i2c_verify_clock_speed.png
Figure 11: Verify I²C clock settings

4

Add an additional client to the existing I²C Driver Instance 0 by clicking on it in the Project Graph. Set the number of clients to 2 (one for the temperature sensor, another for the EEPROM).

add_i2c_clients.png
Figure 12: Add Client

Step 2.3 - Configure USB Device Stack Middleware

1

Add the USB CDC Function Driver module. You can add this by double clicking the module name under Resource Management[MCC] > Device Resources > Libraries > Harmony > USB > Device Stack > CDC Function Driver.

add_usb_cdc_fn_drv.png
Figure 13: Add CDC Function Driver Component

2

Allow the auto-activation of USB Device Layer and USB High Speed Driver. These are required by the CDC Function Driver.

allow_usb_device_layer_autoact.png
Figure 14: Allow the auto-activation of USB Device Layer
allow_usb_high_speed_driver_autoact.png
Figure 15: Allow the auto-activation of USB High Speed Driver
project_graph_after_cdc_module.png
Figure 16: Project Graph after adding USB Middleware

3

Configure the USB High Speed Driver module by clicking it in the Project Graph. Since the E70 Xplained Evaluation Kit is bus-powered, we can uncheck the VBUS sense option.

usb_hsdriver_vbus_off.png
Figure 17: Uncheck Enable VBUS Sense

4

Configure the USB Device Layer module by clicking on it in the Project Graph. Under Product ID Selection, select cdc_com_port_single_demo from the list.

The drivers for this USB device are already installed alongside MPLAB X IDE.

usb_device_pid.png
Figure 18: Select USB Product ID

5

This application uses a single USB CDC Instance. Click on Instance 0 under the CDC Function Driver module in the Project Graph to view its parameters. No further configuration is required.

usb_cdc_instance_verify.png
Figure 19: Verify CDC Instance 0 Parameters

Step 2.4 - Configure ADC Peripheral Library

1

Add the AFEC1 Peripheral Library module. You can add this by double clicking the module name under Resource Management[MCC] > Device Resources > Harmony > Peripherals > AFEC > AFEC1.

AFEC stands for Analog Front End Controller and it's the ADC peripheral available in the SAME70/S70/V70/V71 family of devices.

add_adc_plib.png
Figure 20: Add AFEC1 Peripheral Library
project_graph_after_adc_plib.png
Figure 21: Project Graph after adding AFEC1 Peripheral Library

2

Configure the AFEC1 Peripheral Library module by clicking on it in the Project Graph. Under AFEC1 > ADC Configuration, set the Prescaler spinbox to 24 and the Conversion Mode selection to Software Trigger. The TEMT6000 Ambient Light Sensor is connected to the pin PC31, which is connected internally to AFEC1 Channel 6. Enable channel 6 using the checkbox as shown in Figure 22 under AFEC1 > Channel Configuration > Channel 6 > Enable Channel 6.

configure_adc_plib.png
Figure 22: Configure AFEC1 Peripheral Library



Next Step >

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