Skip to content

Commit

Permalink
MPAE-17989: Initial example project
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebekka Alve authored and Rebekka Alve committed Oct 10, 2024
1 parent 121b9ba commit d044fd1
Show file tree
Hide file tree
Showing 87 changed files with 14,102 additions and 37 deletions.
35 changes: 29 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
# Untracked files in MPLABX projects
/**/build/*
/**/nbproject/*
!/**/nbproject/*.xml
/**/dist/*
/**/.generated_files/*
.generated_files
build
dist
/*/nbproject/*.mk
/*/nbproject/*.bash
/*/nbproject/*.properties
/*/nbproject/private

*ctu-file-list
*.ctu-info

# Studio Folders
/*/[Dd]ebug/
/*/[Rr]elease/
/*/.vs/

#Build Artefacts
*.o
*.d
*.eep
*.elf
*.hex
*.lst
*.map
*.srec
/*/*.yml
/*/__pycache__


32 changes: 24 additions & 8 deletions .main-meta/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"content": {
"metaDataVersion": "1.3.0",
"name": "com.microchip.mcu8.mplabx.project.avr64du32-cnano-usb-vendor-mplab-mcc",
"version": " ",
"displayName": "",
"version": "1.0.0",
"displayName": "AVR64DU32 USB Vendor Class Example",
"projectName": "avr64du32-cnano-usb-vendor-mplab-mcc",
"shortDescription": "This code example demonstrates using the USB Vendor class to transfer data using the USB 2.0 device peripheral on the AVR DU family of MCUs.",
"ide": {
Expand All @@ -19,12 +19,12 @@
}
],
"dfp": {
"name": "",
"semverRange": ""
"name": "AVR-Dx_DFP",
"semverRange": "^2.4.286"
},
"configurator": {
"name": "",
"semverRange": ""
"name": "MCC",
"semverRange": ">=5.7.1"
},
"device": {
"metaDataVersion": "1.0.0",
Expand All @@ -37,8 +37,24 @@
}
},
"author": "Rebekka Alve",
"peripherals": [],
"keywords": [],
"peripherals": [
"USB",
"USB Device Class",
"RTC",
"AC",
"VREF"
],
"keywords": [
"USB",
"USB-C",
"USB Protocol",
"USB 2.0",
"USB Device Class",
"Communication",
"MCC",
"Melody",
"Vendor Class"
],
"additionalData": {
"longDescription": {
"metaDataVersion": "1.0.0",
Expand Down
116 changes: 93 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,114 @@
</picture>
</a>

# Update the title for avr64du32-cnano-usb-vendor-mplab-mcc here

<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
# USB Vendor Data Transfer Demo
This example demonstrates how the Vendor class on the AVR® DU microcontroller (MCU), paired with the AVR64DU32 Curiosity Nano Board, enables data transfer to and from a PC through interrupt, bulk, and isochronous transfers.

## Related Documentation
- [AVR® DU Family Product Page](https://www.microchip.com/en-us/products/microcontrollers-and-microprocessors/8-bit-mcus/avr-mcus/avr-du?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08)
- [AVR64DU32 Chip](https://www.microchip.com/en-us/product/AVR64DU32?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08)

<!-- Any information about an application note or tech brief can be linked here. Use unbreakable links!
In addition a link to the device family landing page and relevant peripheral pages as well:
- [AN3381 - Brushless DC Fan Speed Control Using Temperature Input and Tachometer Feedback](https://microchip.com/00003381/)
- [PIC18F-Q10 Family Product Page](https://www.microchip.com/design-centers/8-bit/pic-mcus/device-selection/pic18f-q10-product-family) -->
### USB Specifications
- [USB 2.0 Specification](https://www.usb.org/document-library/usb-20-specification)

## Software Used

<!-- All software used in this example must be listed here. Use unbreakable links!
- MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide)
- MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers)
- MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
- MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
- Microchip PIC18F-Q Series Device Support (1.4.109) or newer [(packs.download.microchip.com/)](https://packs.download.microchip.com/) -->

- MPLAB® X IDE 6.20.0 or newer [(MPLAB® X IDE 6.20)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide)
- MPLAB® XC8 2.46.0 or newer compiler [(MPLAB® XC8 2.46)](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8)
- [MPLAB® X IDE 6.20](https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) or newer
- [MPLAB® XC8 Compiler 2.46](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) or newer
- [MPLAB® Code Configurator (MCC) 5.5.0](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) or newer

## Hardware Used

<!-- All hardware used in this example must be listed here. Use unbreakable links!
- PIC18F47Q10 Curiosity Nano [(DM182029)](https://www.microchip.com/Developmenttools/ProductDetails/DM182029)
- Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162)
- POT Click board™ [(MIKROE-3402)](https://www.mikroe.com/pot-click) -->
- [AVR64DU32 Curiosity Nano (EV59F82A)](https://www.microchip.com/en-us/development-tool/EV59F82A?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08)


## Setup

<!-- Explain how to connect hardware and set up software. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
### Physical Setup

The AVR DU Curiosity Nano development board has two USB-C ports
1. The Debugger port programs the device with the code example
2. After programming, the cable connected to the Debugger may be disconnected, but it will not affect the example if it remains
3. The Target port must be connected to the PC in order to transfer data between the decive and the PC

### MCC Setup

This section shows how the example is set up using MPLAB® Code Configurator (MCC).

### USB Device Stack Setup

#### USB General Settings
Set the class configuration to Vendor, so that the AVR DU will use the USB vendor protocol to communicate with the PC.
<p><img src="images/mcc_usb_general_settings.png" width="600"/></p>

#### USB Device Descriptors
The Device Descriptors can be left as default.
<p><img src="images/mcc_usb_device_descriptors.png" width="600"/></p>

#### USB Interfaces
For this example, Interface 0 with Alternates 0-4 is required, click "Add Interface" to add them. Alternate 0 will remain as it is.
<p><img src="images/mcc_usb_interfaces.png" width="1000"/></p>

#### USB Vendor Endpoints
We must set up separate endpoints for the interrupt, bulk, and isochronous transfers. To configure the endpoints, click "Add Endpoint" and select the correct configurations corresponding to each Alternate, 1 to 4.
<p><img src="images/mcc_usb_interfaces_endpoints.png" width="1000"/></p>

#### USB0 Power Settings
By default, the target voltage on the AVR64DU32 Curiosity Nano is 3.3V and VUSB is connected to 3.3V using the provided jumper. However, if 5V operation is preferred, the jumper must be removed and the internal USB voltage regulator must be enabled.
<p><img src="images/mcc_usb_power.jpg" width="650"/></p>

### Device Clock Setup
This example is configured to run on 24 MHz under *System Firmware -> CLKCTRL*. The minimum oscillator frequency available for USB on the AVR DU is 12 MHz.
<p><img src="images/mcc_clock_control.png" width="600"/></p>

### USB Voltage Detection Setup
To ensure that the USB peripheral only tries to attach to the bus when the Curiosity Nano is connected to the PC, the Analog Comparator will periodically check if the voltage is within the acceptable range for V<sub>BUS</sub>.

#### Voltage Reference Setup (VREF)
The Voltage Reference is set to 2.048V.
<p><img src="images/mcc_voltage_reference.png" width="600"/></p>

#### Analog Comparator Setup (AC)

##### Analog Comparator Hardware Settings
The Analog Comparator must be enabled by toggling Enable under Hardware Settings.
To measure the correct values, the positive input must be connected to AINP4, while the negative input is set to the DAC Reference.
The DACREF register must be set to a value that can detect the correct voltage level at a minimum of 0.4V. The reference voltage 0.48V (DACREF = 60) used in this project is a little higher to ensure a stable connection. Refer to the [AVR64DU32 Curiosity Nano User Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/AVR64DU32-Curiosity-Nano-UserGuide-DS50003671.pdf) to find the values for the voltage divider on Pin PC3.

<p><img src="images/mcc_analog_comparator_dacref.png" width="500"/></p>

#### Real-Time Counter Setup (RTC)

##### Real-Time Counter Periodic Interrupt Control Settings
The Periodic Interrupt Timer (PIT) is enabled for this example, and the period selection is set to RTC Clock Cycles 1024. This value must be changed according to the clock source selection.
The PIT's Interrupt Flag is also enabled to allow for an interrupt routine.
<p><img src="images/mcc_rtc_pit.png" width="500"/></p>

### Interrupt Manager
Global interrupts must be enabled for the RTC and the USB communication to work.
<p><img src="images/mcc_global_interrupt.jpg" width="500"/></p>


### Device Pin-out Setup
One pin is used for this example: VBUS on PC3 set as input with "Digital Input Buffer disabled". This can be verified under *System Firmware -> Pins*.
<p><img src="images/mcc_pinout.png" width="1000"/></p>
<p><img src="images/mcc_pinout_locks.png" width="1000"/></p>

## Operation

<!-- Explain how to operate the example. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
This example can be tested by following these steps:

1. Generate the MCC code and replace the generated main.c file with the given main.c from the source code
2. Upload the c-code by connecting the Debugger plug on the Curiosity Nano Board (cnano) to the PC
3. Connect the PC to the Target plug on the cnano and install the libusbK driver as shown in [Driver Installation](#driver-installation)
4. Run the python script ``vendor_endpoints.py`` from the given python_test code and see the data transfer

## Driver Installation
A USB driver is required to enumerate vendor devices. The LibusbK driver is recommended to handle isochronous transfers, it can be downloaded from here: https://zadig.akeo.ie/ (choose libusbK after downloading).
Make sure to select the correct device from the drop-down menu, with VID = 0X04D8 and PID = 0X0B0A.
If the device does not show up, select *List all devices->Options*.
<p><img src="images/zadig_installation.png" width="600"/></p>

## Summary

<!-- Summarize what the example has shown -->
This example has shown how the USB Vencor class can be used on an AVR DU to transfer data to and from a PC, using interrupt, bulk and isocronous transfer.
113 changes: 113 additions & 0 deletions avr64du32-cnano-usb-vendor-mplab-mcc.X/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL


# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib


# build
build: .build-post

.build-pre:
# Add your pre 'build' code here...

.build-post: .build-impl
# Add your post 'build' code here...


# clean
clean: .clean-post

.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.

.clean-post: .clean-impl
# Add your post 'clean' code here...


# clobber
clobber: .clobber-post

.clobber-pre:
# Add your pre 'clobber' code here...

.clobber-post: .clobber-impl
# Add your post 'clobber' code here...


# all
all: .all-post

.all-pre:
# Add your pre 'all' code here...

.all-post: .all-impl
# Add your post 'all' code here...


# help
help: .help-post

.help-pre:
# Add your pre 'help' code here...

.help-post: .help-impl
# Add your post 'help' code here...



# include project implementation makefile
include nbproject/Makefile-impl.mk

# include project make variables
include nbproject/Makefile-variables.mk
Loading

0 comments on commit d044fd1

Please sign in to comment.