![GigaDevice Semiconductor GD32F20 Series User Manual Download Page 888](http://html.mh-extra.com/html/gigadevice-semiconductor/gd32f20-series/gd32f20-series_user-manual_2225801888.webp)
GD32F20x User Manual
888
3.
Program USBFS_DIEPxLEN or USBFS_DOEPxLEN register. PCNT is the number of
packets in a transfer and TLEN is the total bytes number of all the transmitted or received
packets in a transfer.
For IN endpoint
:
If PCNT=1, the single packet
’
s size is equal to TLEN. If PCNT>1, the
former PCNT-1 packets are considered as max-packet-length packets whose size are
defined by MPL field in USBFS_DIEPxCTL register, and the last packet
’
s size is
calculated based on PCNT, TLEN and MPL. If a zero-length packet is required to be sent,
it should program TLEN=0, PCNT=1.
For OUT endpoint
:
Because the application doesn
’
t know the actual received data size
before the OUT transaction finishes, TLEN can be set to a maximum possible value
supported by Rx FIFO.
4.
Set EPEN bit in USBFS_DIEPxCTL or USBFS_DOEPxCTL register to enable the
endpoint.
Endpoint disable sequence
The endpoint can be disabled anytime when the EPEN bit in USBFS_DIEPxCTL or
USBFS_DOEPxCTL registers is cleared.
IN transfers operation sequence
1. Initialize USBFS global registers.
2.
Initialize and enable the IN endpoint.
3.
Write packets into the endpoint’s Tx FIFO. At any time, a data packet is written into the
FIFO, USBFS decreases the TLEN field in USBFS_DIEPxLEN register by the written
packet’s size.
4.
When an IN token received, USBFS transmits the data packet, and after the transaction
finishes on USB bus, PCNT in USBFS_DIEPxLEN register is decreased by 1. If the
transaction finishes successfully (ACK handshake received), the ACK flag is triggered.
Otherwise, the status flags reports the transaction result.
5.
After all the data packets in a transfer have been successfully sent on USB bus, USBFS
generates TF flag to indicate that the transfer successfully is finished and the IN endpoint
is disabled.
OUT transfers operation sequence
1. Initialize USBFS global registers.
2.
Initialize the endpoint and enable the endpoint.
3.
When an OUT token is received, USBFS receives the data packet or response with an
NAK handshake based on the status of Rx FIFO and register configuration. If the
transaction is finished successfully (USBFS receives and saves the data packet into Rx
FIFO successfully and sends ACK handshake on USB bus), PCNT in
USBFS_DOEPxLEN register is decreased by 1 and the ACK flag is triggered, otherwise,
Summary of Contents for GD32F20 Series
Page 191: ...GD32F20x User Manual 191 Bits Fields Descriptions 31 0 TRNDATA 31 0 32 Bit Random data ...
Page 290: ...GD32F20x User Manual 290 conversion is ongoing ...
Page 325: ...GD32F20x User Manual 325 15 0 ALRM 15 0 RTC alarm value low ...
Page 385: ...GD32F20x User Manual 385 ...
Page 523: ...GD32F20x User Manual 523 clears AERR bit by writing 0 to it ...