UxDIL Software Collection
This folder contains the template files for a user defined USB device firmware. A user defined device is the best choice, if special requirements are given, such as a higher data throughput, lower latency times and the transmission of greater data blocks.
The advantages of a user defined USB device:
Any transfer type (control, bulk, interrupt and isochronous) is supported.
Any endpoint of the microcontroller can be used (multiple transfer channels).
No transfer protocol restrictions.
Usage of multiple USB configurations and interfaces.
Easy and flexible code handling for host application, if a suitable interface library is available for the used developing software.
The disadvantages:
Special drivers and driver installation is required.
More difficult code handling for host application, if no suitable interface library available for the used developing software.
usb_user_config.h
This file contains general agreements. You will modify this file for your purposes. A special point of interest will be the following defines:
STR_MANUFACTURER |
Your vendor name. Insert your company or personal name. |
STR_PRODUCT |
Your product name. Insert the name of the product. |
USESN |
0: no serial number (new driver installation, if device is plugged in another USB plug) 1: fixed serial number in flash memory 2: a changeable serial number (e.g. from EEPROM), loaded into variable RAMSN (usb_serial.h) by the firmware If a serial number is used, the drivers for the device will be installed only one time, independent from the used plug. |
STR_SERIAL_NUMBER |
Insert the fixed serial number here, if USESN=1 |
VENDOR_ID |
Your official vendor ID. Don't use the predefined ID of the template or any you like, if you want to sell the product! |
PRODUCT_ID |
Your official product ID. Don't use the predefined ID of the template or any you like, if you want to sell the product! |
POWERING |
Set to SELFPOWERED and/or BUSPOWERED, if your device is powered by his own supply and/or via USB plug. |
MAXPOWER |
Insert the bus powered current consumption of the device in milliamperes. The maximum allowed value is 500 (mA). |
ENDPOINT0_SIZE |
The transmission buffer size for control transfers (endpoint 0). Use a value like 16, 32 or 64 byte. |
USERDEFCONTROLS |
Uncomment this definition, if you want to use your own control transfer data exchanges. The callback routine “usb_controlrequest()” (main.c) will be called at incoming data over endpoint 0. |
NUMINTERFACES |
Number of supported interfaces. An interface is a configuration set for the endpoints. At least one interface has to be defined. Up to 3 interfaces are supported by the template library. |
EP_CONFIG |
Configuration of each endpoint (except endpoint 0) of the microcontroller. A definition contains the transfer type, buffer size and buffer equipment. Use the following constants to define the transfer type (as long as supported by the microcontroller):
Use buffer size values like 8, 16, 32, 64, 128, 256 or 512 byte. Take a look to the data sheet of the microcontroller, which is the maximum allowed value. Note, that the usage of more endpoints reduces the maximum allowed values. For the buffer equipment use the constant EP_SINGLE_BUFFER or EP_DOUBLE_BUFFER. Refer to the data sheet for more information. |
Be careful in changing of other definitions to keep a well working USB device!
usb_user.h
This file contains the definitions of some routines, which are needed. Usually no changes has been made!
usb_user.c
This file contains the USB routine code for general and user defined USB communication. Usually no changes has been made!
main.c
Use this file as a base for your new project! The template contains the callback routines, which will be automatically called by the specific event. For example “usb_ep()” is called, if data is received from host. On the other hand you can call “usb_txdata()” to return data to host. The main routine has to contain the routine call “usb_init()” (initialize USB) and “sei()” (enable interrupts).
Make the template main.c file as your main file. Add the usb_user files to the project. After compiling, upload into the microcontroller and connecting with the PC, it should find a new USB device.
For more information refer to the examples.