Functional Description
1689
SLAU723A – October 2017 – Revised October 2018
Copyright © 2017–2018, Texas Instruments Incorporated
Universal Serial Bus (USB) Controller
null packet may be sent at the end of the series if the size of the data block is an exact multiple of the
maximum packet size). The DMA may be used in either device mode or host mode to avoid the overhead
of having to interrupt the processor after each individual packet, and instead, only interrupting the
processor after the transfer has completed. The following sections outline the basic actions that are
involved in using the DMA alongside some standard types of Bulk Tx and Bulk Rx transfers.
27.3.6.3.1 Using DMA with Bulk Tx Endpoints
For Tx endpoints, the DMA request line is high when the endpoint FIFO is able to accept a data packet,
and goes low when MAXLOAD transmit bytes have been loaded into the FIFO. Alternatively, the request
line is held low when the TXRDY bit in USBTXCSRLn register is set. To use DMA to send a large block of
data to the USB host over a Bulk Tx endpoint, we recommend setting up the DMA controller and the USB
as follows:
•
The DMA controller should be programmed to perform a burst DMA read of the maximum size of
packet for the endpoint (512 bytes for high speed, 64 bytes for full speed) when the DMA request line
for the endpoint transitions from low to high. The controller should keep performing these burst reads
on each DMA request until the entire data block has been transferred. (The last burst may however be
of less than the maximum packet size). It should then interrupt the CPU.
•
The USB should be programmed to enable Autoset and DMA Request Mode 1 by setting the
AUTOSET, DMAEN and DMAMOD bits in the USBTXCSRHn register.
Programmed like this, the USB DMA request line is held high whenever there is space in its FIFO to
accept a packet. Further, the TXRDY bit is automatically set after the DMA controller has loaded the FIFO
with a packet of the maximum packet size. The packet is then ready to be sent to the host. When the last
packet has been loaded by the DMA controller, the controller interrupts the processor. If the last packet
loaded is less than the maximum packet size, the TXRDY bit is not set and therefore needs to be set
manually (that is, by the CPU) to allow the last packet to be sent. The TXRDY bit also needs to be set
manually if the last packet is of the maximum packet size and a null packet is to be sent to indicate the
end of the transfer.
NOTE:
If, when operating in host mode, the USB fails to successfully transmit a packet three times,
the ERROR bit in the USBTXCSRLn register becomes set and the DMA request line is
disabled until this ERROR bit is cleared again. It should also be noted that the DMAMOD bit
in the USBTXCSRHn register must not be cleared either before or in the same cycle as the
corresponding DMAEN bit is cleared.
27.3.6.3.2 Using DMA with Bulk RX Endpoints
The behavior of the DMA request line for an Rx Endpoint depends on the DMA Request Mode
(DMAMOD) selected through the USB Receive Control and Status Endpoint n High (USBRXCSRHn)
register. In DMA Request Mode 0, the Rx DMA request line is held high when a data packet is available in
the endpoint FIFO and is low either when the last byte of the data packet has been read, or when the
RXRDY bit in USB Receive Control and Status Endpoint n Low (USBRXCSRLn) is cleared. In DMA
Request Mode 1, the DMA request line only goes high when the packet received is of the maximum
packet size (as set in the USBRXMAXPn register). If the packet received is of some other size, the DMA
request line stays low with the result that the packet remains in the FIFO with the RXRDY bit set. This
causes an Rx Endpoint interrupt to be generated (if enabled).
The DMA Request Modes are primarily designed to be used where large packets of data are transferred
to a Bulk endpoint. The USB protocol requires such packets to be split into a series of packets of
maximum packet size (512 bytes for high speed, 64 bytes for full speed). The last packet in the series
may be less than the maximum packet size (or a null packet if the total size of the transfer is an exact
multiple of the maximum packet size) and the receiver may interpret this short packet as signaling the end
of the transfer. DMA Request Mode 1 can be used, with a suitably programmed DMA controller, to avoid
the overhead of having to interrupt the processor after each individual packet instead just interrupting the
processor after the transfer has completed.