AT32F425
Series Reference Manual
2022.03.30
Page 371
Ver 2.01
application can first write into the endpoint control register before writing the data into the data FIFO.
Normally, except for setting the endpoint enable bit, the application must do a read modify write on the
OTGFS_DIEPCTLx register to avoid modifying the contents of the register. If the space is enough, the
application can write multiple data packets for the same endpoint into the transmit FIFO. For the periodic
IN endpoints, the application must write packets for only one frame. It can write packets for the next
periodic transfer only after the previous transfer has been completed.
20.5.4.14
Non-periodic (bulk and control) IN data transfers
To initialize the controller after power-on reset, the application must perform the steps list in OTGFS
Initializtion. Before communicating with a host, the controller must follow the steps defined in Device
Initializtion to initialize endpoints.
【
Application requirements
】
1. For IN tranfers, the Transfer Size bit in the Endpoint Transfer Size register indicates a payload that
contains multiple largest-packet-size packets and a short packet. This short packet is transmitted at the
end of the transfer.
To transmit several largest-packet-size packets and a short packet:
Transfer size [epnum] = n * mps[epnum] + sp (n is an integer ≥ 0 and 0 ≤ sp < mps[epnum])
If (sp > 0), then packet count [epnum] = n + 1
.
Otherwise, packet count [epnum] = n
To transmit a single zero-length data packet:
Transfer size [epnum] = 0x0
Packet count [epnum] = 0x1
To transmit several largest-packet-size packets and a zero-length data packet (at the end of the
transfer), the application must split the transfer into two parts. First send the largest-packet-size
packets and then the zero-length data packet alone.
First transfer: Transfer size [epnum] = n * mps[epnum]; Packet count = n;
Second transfe: Transfer size [epnum] = 0x0; Packet count = 0x1;
2. If an endpoint is enabled for data transfers, the controller updates the Transfer size register. At the
end of the IN transfer (indicated by endpoint disable interrupt bit), the application must read the Transfer
size register to determine how much data in the transmit FIFO have already been sent on the USB line.
3. Data fetched in the transmit FIFO = Application-programmed initial transfer size – Controller-updated
final transfer size
Data transmitted on USB = (Application-programmed initial packet count – Controller-updated
final packet count) * mps[epnum]
Data to be transmitted on USB = Application-programmed initial transfer size – Data transmitted
on USB
【
Internal data flow
】
1. The application must set the transfer size and packet count bits in the endpoint control registers and
enable the endpoint to transmit the data.
2. The application must also write the required data to the transmit FIFO of the endpoint.
3. Each time a data packet is sent to the transmit FIFO by the application the transfer size for this
endpoint is decremented with the packet size. The application must continue to write data until the
transfer size of the endpoint becomes 0. After writing data to the FIFO, the “packet count in the FIFO” is
incremented (this is a 3-bit count for each IN endpoint transmit FIFO data packet, which is internally
maintained by the controller. For an IN endpoint FIFO, the maximum number of packets maintained by
the controller at any time is 8). For non-zero-length packets, a separate flag is set for each FIFO, without
any data in the FIFO.
4. After the data is written to the transmit FIFO, the controller reads them upon receiving an IN token.
For each non-synchronous IN data packet transmitted with an ACK handshake signal, the number of
packets for the endpoint is decremented by 1, until the packet count becomes 0. The packet count is not
decremented due to a timeout.
5. For zero-length data packets (indicated by an internal zero-length flag), the controller sends zero-
length packets according to the IN token, and the packet count is decremented automatically.