USB Transfers
1134
SLAU208Q – June 2008 – Revised March 2018
Copyright © 2008–2018, Texas Instruments Incorporated
USB Module
42.3.1.1 Control Write Transfer
The host uses a control write transfer to write data to the USB device. A control write transfer consists of a
setup stage transaction, at least one output data stage transaction, and an input status stage transaction.
The stage transactions for a control write transfer are:
•
Setup stage transaction:
1. Input endpoint 0 and output endpoint 0 are initialized by programming the appropriate USB
endpoint configuration blocks. This entails enabling the endpoint interrupt (USBIIE = 1) and
enabling the endpoint (UBME = 1). The NAK bit for both input endpoint 0 and output endpoint 0
must be cleared.
2. The host sends a setup token packet followed by the setup data packet addressed to output
endpoint 0. If the data is received without an error, then the UBM writes the data to the setup data
packet buffer, sets the setup stage transaction bit (SETUPIFG = 1) in the USB Interrupt Flag
register (USBIFG), returns an ACK handshake to the host, and asserts the setup stage transaction
interrupt. Note that as long as SETUPIFG = 1, the UBM returns a NAK handshake for any data
stage or status stage transactions regardless of the endpoint 0 NAK or STALL bit values.
3. The software services the interrupt, reads the setup data packet from the buffer, and then decodes
the command. If the command is not supported or invalid, the software should set the STALL bit in
the output endpoint 0 configuration register (USBOEPCNFG_0) and the input endpoint 0
configuration register (USBIEPCNFG_0) . This causes the device to return a STALL handshake for
any data or status stage transaction. For control write transfers, the packet ID used by the host for
the first data packet output is a DATA1 packet ID and the TOGGLE bit must match.
NOTE:
When using USBIV, SETUPIFG is cleared upon reading USBIV. In addition, the NAK on
input endpoint 0 and output endpoint 0 are also cleared. In this case, the host may send or
receive the next setup packet even if MSP430 did not perform the first setup packet. To
prevent this, first read the SETUPIFG directly, perform the required setup, and then use the
USBIV for further processing.
NOTE:
The priority of input endpoint 0 is higher than the setup flag inside USBIV (SETUPIFG).
Therefore, if both the USBIEPIFG.EP0 and SETUPIFG are pending, reading USBIV gives
the higher priority interrupt (EP0) as opposed to SETUPIFG. Therefore, read SETUPIFG
directly, process the pending setup packet, then proceed to read the USBIV.
•
Data stage transaction:
1. The host sends an OUT token packet followed by a data packet addressed to output endpoint 0. If
the data is received without an error, the UBM writes the data to the output endpoint buffer
(USBOEP0BUF), updates the data count value, toggles the TOGGLE bit, sets the NAK bit, returns
an ACK handshake to the host , and asserts the output endpoint interrupt 0 (OEPIFG0).
2. The software services the interrupt and reads the data packet from the output endpoint buffer. To
read the data packet, the software first needs to obtain the data count value inside the
USBOEPBCNT_0 register. After reading the data packet, the software should clear the NAK bit to
allow the reception of the next data packet from the host.
3. If the NAK bit is set when the data packet is received, the UBM simply returns a NAK handshake to
the host. If the STALL bit is set when the data packet is received, the UBM simply returns a STALL
handshake to the host. If a CRC or bit stuff error occurs when the data packet is received, then no
handshake is returned to the host.
•
Status stage transaction:
1. For input endpoint 0, the software updates the data count value to zero, sets the TOGGLE bit, then
clears the NAK bit to enable the data packet to be sent to the host. Note that for a status stage
transaction, a null data packet with a DATA1 packet ID is sent to the host.
2. The host sends an IN token packet addressed to input endpoint 0. After receiving the IN token, the
UBM transmits a null data packet to the host. If the data packet is received without errors by the
host, then an ACK handshake is returned. The UBM then toggles the TOGGLE bit and sets the
NAK bit.