AT90USBxxx USB software library for dual role devices
Use of this program is subject to Atmel's End User License Agreement.
Please read file lic_page for copyright notice.
This embedded application source code illustrates how to implement a USB interfaced application over the AT90USBxxx controller.
As the AT90USBxxx implements a device/host usb controller, the embedded application can operates in one of the following usb operating modes:
- USB device
- USB reduced host controller
- USB dual role device (depending on the ID pin)
To optimize embedded code/ram size and reduce the number of source modules, the application can be configured to use one and only one of these operating modes.
This sample application can be configured for both STK525 or AT90USBKey hardware, see TARGET_BOARD define value in config.h file.
This source code is usable with the following compilers:
- IAR Embedded Workbench (5.11A and higher)
- AVRGCC (WinAVR 20080411 and higher).
Support for other compilers may required modifications or attention for:
- compiler.h file
- special registers declaration file
- interrupt subroutines declarations
- V2.0.2
USB Device:
- Fix bug about back drive voltage on D+ after VBus disconnect (USB Certification)
- Remove VBus interrupt and manage VBus state by pooling
- Fix bug during attach (the interrupt must be disable during attach to don't freeze clock)
USB Host:
- Improve USB Host behavior
- Fix bug on stall management with dual banks
- improve disconnection detection
- V2.0.1
USB Stack
- Add three possibilities for SN on USB
- Move VBus interrupt to VBus pooling
- Fix USB constant about Device Status
- Improve USB protocol to have a USB chap9 compliance
New watchdog driver
- V2.0.0 and before
- Old versions
By default the sample code is delivered with a simple preconfigured dual role USB application. It means that the code generated allows to operate as a device or a host depending on the USB ID pin:
- Attached to a mini B plug (ID pin unconnected) the application will be used in the device operating mode
- Attached to a mini A plug (ID pin tied to ground) the application will operate in reduced host mode
Thus two instances of this application can be connected together with a miniA-miniB cable.
- The host operating mode of the application (that we call A device) can manage the connection and the enumeration of a device application connected in device operating mode (that we call B device). Once the device has been enumerated, the host high level application can operate USB applicative exchanges with the B device. Here the sample host application writes 64 byte through a USB OUT pipe and read back these data with an IN pipe.
- The device operating mode of the application (B device) answers to the enumeration requests (setup requests) of the host controller. Once it has been properly enumerated the high level device application receives 64 data through its OUT enpoint and when the host controller request for an IN exchange on its IN endpoints, sends it back (loopback application).
As illustrated in the figure bellow, the application entry point is located is the main.c file. The main function first performs the initialization of a scheduler module and then runs it in an infinite loop. The scheduler is a simple infinite loop calling all its tasks defined in the conf_scheduler.h file. No real time schedule is performed, when a task ends, the scheduler calls the next task defined in the configuration file (conf_scheduler.h).
The sample dual role application is based on three different tasks:
- The usb_task (usb_task.c associated source file), is the task performing the USB low level enumeration process in device or host mode. Once this task has detected that the usb connection is fully operationnal, it updates different status flags that can be check within the high level application tasks.
- The device template task (device_template_task.c associated source file) performs the high level device application operation. Once the device is fully enumerated (DEVICE SETUP_SET_CONFIGURATION request received), the task checks for received data on its OUT endpoint and transmit these data on its IN endpoint.
- The host template tak (host_template_task.c associated file) performs the high level host application operation. Ih the "B device" is correctly connected and enumerated, the task sends and receives data with the USB bus.
The sample application is configured to implements both host and device functionnalities. Of course it can also be configured to be used in device or reduced host only mode (See conf_usb.h file). Depending on the USB operating mode selected, the USB task will call either the usb_host_task (usb_host_task.c), either the usb device task (usb_device_task.c) to manage chapter 9 requests. In such case, the corresponding template_device_task or template_host_task can be removed from the scheduled tasks (see conf_scheduler.h). - Note:
- The B device descriptors used for this sample application are not directly usable for enumeration with a standard Pc host system. Please refers to ATMEL website for real devices applications examples (HID mouse, HID keyboard, MassStorage, CDC ... )
- Todo:
- Implements the required mechanism for On the Go (OTG) compliance: SRP, HNP and role exchange detection/requests.
Generated on Mon Sep 14 13:24:11 2009 for ATMEL by
1.5.3