User manual
...the world's most energy friendly microcontrollers
2012-04-24 - Giant Gecko Family - d0053_Rev0.96 318
www.energymicro.com
1. Before setting up an IN transfer, the application must ensure that all data to be transmitted as part of
the IN transfer is part of a single buffer, and must program the size of that buffer and its start address
(in DMA mode) to the endpoint-specific registers.
2. For IN transfers, the Transfer Size field in the Endpoint Transfer Size register denotes a payload
that constitutes multiple maximum-packet-size packets and a single short packet. This short packet
is transmitted at the end of the transfer.
a. To transmit a few maximum-packet-size packets and a short packet at the end of the transfer:
• Transfer size[epnum] = n * mps[epnum] + sp
(where n is an integer > 0, and 0 < sp < mps[epnum]. A higher value of n reduces the periodicity
of the USB_DOEPx_INT.XFERCOMPL interrupt)
• If (sp > 0), then packet count[epnum] = n + 1. Otherwise, packet count[epnum] = n
b. To transmit a single zero-length data packet:
• Transfer size[epnum] = 0
• Packet count[epnum] = 1
c. To transmit a few maximum-packet-size packets and a zero-length data packet at the end of the
transfer, the application must split the transfer in two parts. The first sends maximum-packet-size
data packets and the second sends the zero-length data packet alone.
• First transfer: transfer size[epnum] = n * mps[epnum]; packet count = n;
• Second transfer: transfer size[epnum] = 0; packet count = 1;
d. The application can only transmit multiples of maximum-packet-size data packets or multiples of
maximum-packet-size packets, plus a short packet at the end. To transmit a few maximum-packet-
size packets and a short packet at the end of the transfer, the following conditions must be met.
• transfer size[epnum] = n * mps[epnum] + sp (where n is an integer > 0, and 0 < sp < mps[epnum])
• If (sp > 0), packet count[epnum] = n + 1 Otherwise, packet count[epnum] = n;
• mc[epnum] = number of packets to be sent out in a frame.
e. The application cannot transmit a zero-length data packet at the end of transfer. It can transmit a
single zero-length data packet by itself. To transmit a single zero-length data packet,
• transfer size[epnum] = 0
• packet count[epnum] = 1
• mc[epnum] = packet count[epnum]
3. In DMA mode, the core fetches an IN data packet from the memory, always starting at a DWORD
boundary. If the maximum packet size of the IN endpoint is not a multiple of 4, the application must
arrange the data in the memory with pads inserted at the end of a maximum-packet-size packet so
that a new packet always starts on a DWORD boundary.
4. Once an endpoint is enabled for data transfers, the core updates the Transfer Size register. At the end
of IN transfer, which ended with a Endpoint Disabled interrupt, the application must read the Transfer
Size register to determine how much data posted in the transmit FIFO was already sent on the USB.
• Data fetched into transmit FIFO = Application-programmed initial transfer size - core-updated final
transfer size
• Data transmitted on USB = (application-programmed initial packet count - Core updated final packet
count) * mps[epnum]
• Data yet to be transmitted on USB = (Application-programmed initial transfer size - data transmitted
on USB)
5. The application can schedule data transfers for multiple frames, only if multiples of max packet sizes
(up to 3 packets), must be transmitted every frame. This is can be done, only when the core is
operating in DMA mode.
• ((n*USB_DIEPx_TSIZ.MC) - 1)*USB_DIEPx_CTL.MPS <= USB_DIEPx_TSIZ.XFERSIZE <=
n*USB_DIEPx_TSIZ.MC*USB_DIEPx_CTL.MPS
• USB_DIEPx_TSIZ.PKTCNT = n*USB_DIEPx_TSIZ.MC
• n is the number of frames for which the data transfers are scheduled. Data Transmitted per frame
in this case is USB_DIEPx_TSIZ.MC*USB_DIEPx_CTL.MPS in all frames except the last one. In
frame n, the data transmitted is (USB_DIEPx_TSIZ.XFERSIZE – (n – 1) * USB_DIEPx_TSIZ.MC
* USB_DIEPx_CTL.MPS)