SAM D21 USB Overview

Introduction

Universal Serial Bus (USB) is an industry standard for communication between electronic devices. USB peripheral support in the SAM D21 device offers both peripheral device and embedded host modes having eight endpoints/pipes (each address having one input and one output endpoint).

To optimize the endpoint/pipe data transfers, the USB peripheral features a built-in direct memory access (DMA) which reads/writes to/from the internal SRAM during a USB transaction without CPU intervention.

In addition, the USB peripheral also has support for ping-pong operation and multi-packet transfers. This reduces the number of software interventions and interrupts required to manage a USB transaction.

It is not possible to configure the device and host registers at the same time, as they share the same address space for their registers. So, the USB peripheral can be configured in only one of the modes at any given point in time.

SAM D21 USB uses CLK_USB_APB for register access and CLK_USB_AHB for the DMA access to the internal SRAM. It uses GCLK_USB as a reference clock. The figure below shows the USB peripheral block diagram.

SAM-D21-USB-Peripheral.PNG

Features

  • USB 2.1 Specification Compliance with Link Power Management (LPM-L1) Protocol Support
  • Embedded host and device mode support
  • Full Speed and Low-Speed Support
  • Built-in DMA for data transfers
  • Multi-packet transfers
  • Ping-pong mode
  • On-chip USB transceiver
  • On-chip pull-up and pull-down resistors
  • On-chip USB serial resistors

Common Features for Host and Device Modes

Multi-packet Transfers

Typically, an endpoint can transfer a maximum of endpoint packet size in a single USB transfer. For large amounts of data, the software must manually split the data into packets and send them through the USB. When a multi-packet transfer is used, the USB peripheral itself splits the data into multiple packets and transfers them automatically on each USB data request. Thus, it enables transfer of data larger than the endpoint size without further interrupts or CPU intervention and provides higher data transfer rate, as shown in the figure below.

USB-Transfer-with-Multi-packet.PNG

Ping-pong Operation

When the ping-pong mode/dual-bank is configured for an endpoint/pipe, it uses the data buffers for both the input and the output endpoints/pipes of an endpoint/pipe address in the same direction. For example, if Endpoint 1 IN is configured to use ping-pong mode, it uses the data buffer of Endpoint 1 OUT for dual-banking. (Endpoint 1 OUT cannot be used when Endpoint 1 IN is used in ping-pong mode). An example of a ping-pong operation is shown below.

Ping-Pong-Operation-in-Endpoint-Pipe.PNG

USB Device Mode

USB Device Mode Features

SAM D21 USB peripheral has the following features specific to USB device mode:

  • USB clock recovery mode for digital frequency-locked-loop (DFLL) in USB device mode (Crystal-less USB operation)
  • Feedback Endpoint Support
  • No endpoint size limitation

Crystal-less Operation

SAM D21 provides an option to use the USB Start-Of-Frame (SOF) signal as a reference signal for DFLL to generate the required 48 MHz for GCLK_USB. When the USB Clock Recovery Mode (USBCRM) is enabled in the DFLL, the SOF signal from the USB host will be used as the reference clock for DFLL. An auto-jitter mechanism is enabled with USBCRM to manage the jitter within the USB specification limit. This feature eliminates the requirement of an external crystal in USB device applications.

Endpoint Management

The SAM D21 USB device mode supports a maximum of eight endpoint addresses. Each address can be configured to have an input and an output endpoint. All the endpoints can be configured in any of the four transfer types: control, interrupt, bulk, or isochronous.

SAM D21 uses an endpoint descriptor table to manage the endpoint configuration and status. The endpoint descriptor and the endpoint data buffer can be physically allocated anywhere in the internal RAM. The USB controller accesses the endpoint data directly through the AHB master with the help of the built-in DMA. Memory usage for each endpoint depends on the endpoint configuration (size, number of banks, etc.) and you can allocate it dynamically based on the application requirements.

Suspend and Remote Wake-up

When a suspend condition is detected on the USB bus, the USB pads are put into an idle state (low power consumption mode). On a resume signal from the host, the pads are back to the active state. The USB operations resume receiving a downstream signal from the host. If remote wake-up is enabled in the device, it can send an Upstream Resume to the host to resume the USB operations. The rebroadcasted resume from the USB host is managed by the USB hardware and sets an interrupt flag when the resume event is completed. The figure below shows the USB pad behavior on suspend and resume events.

Pad-Behavior-on-Suspend-and-Resume-Event.PNG

Link Power Management Protocol

SAM D21 USB device supports the Link Power Management Protocol (LPM-L1) and complies with the USB 2.0 LPM-L1 ECN.

LPM-L1 allows a USB host to configure the USB device into an inactive state much faster than the normal USB suspend mode (which requires 3 ms of bus inactivity). It also provides much faster wake-up times in the order of microseconds compared to the generic resume by host or upstream resume by the device (which requires nearly 3 to 30 ms). Further, it imposes no restrictions on the current drawn from the VBUS compared to SUSPEND mode (which is limited to 500 μA to 2 mA).

An LPM transaction from host to device is necessary for the device to enter the L1 state. This L1-SLEEP state would occur after 9 μs from receiving the LPM transaction. The remote wake-up feature from the device can be enabled/disabled through the LPM transaction. The L1-SLEEP exit time is specified by the BESL parameter provided through the USB descriptors. The device can conserve power in the L1-SLEEP state by entering any of the sleep modes with the constraint that the wake-up latency should satisfy the BESL parameter.

If the LPM-L1 support is not enabled, the device ignores the LPM transactions from the USB host and no handshake is returned.

SOF Clock Output

The USB SOF signal can be brought out to the SOF 1 kHz pin, that way it can be fed to external components as a reference/synchronization signal.

Feedback Endpoint

SAM D21 USB supports the creation of explicit feedback endpoints. Feedback endpoints are generally used in asynchronous USB Audio applications to provide an explicit feedback on the isochronous endpoints usage in the device. It provides a mechanism to the host on adjusting the data rate based on the device operation. A feedback endpoint is an interrupt endpoint having the same endpoint number as the isochronous endpoint but operating in the opposite direction.

Example:

  • Endpoint Address 1 OUT: Isochronous (Audio data from the host to the device).
  • Endpoint Address 1 IN: Interrupt (Provides feedback on the audio data usage to the host).

USB Embedded Host Mode

USB Embedded Host Mode Features

SAM D21 USB peripheral has the following features specific to USB embedded host mode:

  • Multiplexed virtual pipe Support
  • Phase-locked SOF Support
  • No pipe size limitation
  • Feedback endpoint support

Pipe Configuration

The SAM D21 USB host mode supports a maximum of eight physical pipe addresses. Each address can be configured to have an input and an output pipe. There is no pipe size limitation. All the pipes can be configured in any of the four transfer types: control, interrupt, bulk or isochronous. In addition to this functionality, the SAM D21 USB provides the feature to multiplex virtual pipes to a single physical pipe.

SAM D21 uses a pipe descriptor table to manage the pipe configuration and status. The pipe descriptor and the pipe data buffer can be physically allocated anywhere in the internal RAM. The USB controller accesses the pipe data directly through the AHB master with the help of the built-in DMA. Pipes can be configured to use a maximum of two memory banks.

For IN/OUT transactions, the USB will send the IN/OUT requests for the pipe until it is frozen. When the pipe is configured to use multiple banks, the USB peripheral will automatically switch to the next bank (the next bank must be ready) for IN/OUT transactions.

The pipes can be frozen by the hardware in one of the following cases:

  • After the pipe is enabled
  • On receiving a STALL handshake
  • On completing a transfer with a pipe error
  • On the completion of an LPM transaction (on receiving or handshake or on time-out)

If the software tries to freeze a pipe which is in the middle of a USB transaction, the USB completes the ongoing USB transaction before freezing the pipe.

Suspend and Remote Wake-up

On disabling the SOF generation, the USB host puts the bus into an idle state. After 3 ms of inactivity in the bus, the connected USB device enters the suspend mode as per the USB specifications.

While enabling the Suspend state, if a bank is ready for an OUT transaction, the USB automatically exits the Suspend state to start the OUT transaction.

The USB host can be restored to its active state by sending a USB Resume to the device or on receiving an Upstream Resume from the device.

Link Power Management Protocol

SAM D21 USB host supports the Link Power Management Protocol and complies with the USB 2.0 LPM-L1 ECN. It supports the hardware generation of LPM transactions required to enter the L1-SLEEP state. The USB host enters the L1-SLEEP state only on receiving a successful handshake from the device. The host will cease the generation of the SOF in the L1-SLEEP state. The host exits the L1 state on receiving an L1 Upstream Resume from the device or by generating L1 Resume or a Downstream Resume. If it is an L1 Resume, the timing is provided by the BESL parameter.

After resuming from the L1-SLEEP state, the host starts Start-Of-Frame generation.

Phase Locked SOF

SAM D21 USB host generates phase-locked SOF which are typically used by Synchronous Endpoints in USB Audio applications where the audio stream is synchronized with the USB SOF signal. Here, the SOFs will be generated every 1 ms or an integer multiple of 1 ms (across idle/suspend/resume state) to maintain the synchronicity for synchronous endpoints.

Multiplexed Virtual Pipes

SAM D21 USB allows the mapping of one physical pipe to different logical pipes creating a virtual pipe configuration. To implement a virtual pipe for multiple logical pipes, context saving (Pipe registers and Pipe configuration data in the descriptor table) and switching of pipe configurations should be done before using the logical pipe.

 Learn More

 
Event System Configuration
Learn more >
 
Event System Example Project (GCC)
Learn more >
© 2018 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.