GD32W51x User Manual
835
1.
Initialize USBFS global registers.
2.
Initialize and enable the IN endpoint.
3.
Write packets into the endpoint’s Tx FIFO. Each 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 are successfully sent on USB bus, USBFS
generates TF flag to indicate that the transfer successfully finishes and disables the IN
endpoint.
OUT transfers operation sequence
1.
Initialize USBFS global registers.
2.
Initialize the endpoint and enable the endpoint.
3.
When an OUT token 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
finishes 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, the status flags report
the transaction result.
4.
After all the data packets in a transfer are successfully received on USB bus, USBFS
pushes a TF status entry into the Rx FIFO on top of the last packet data. Thus after
reading and poping all the received data packet, the TF status entry is read, USBFS
generates TF flag to indicate that the transfer successfully finishes and disables the OUT
endpoint.
24.6.
Interrupts
USBFS has two interrupts: global interrupt and wake-up interrupt.
The source flags of the global interrupt are readable in USBFS_GINTF register and are listed
in
Table 24-2. USBFS global interrupt
.
Table 24-2. USBFS global interrupt
Interrupt Flag
Description
Operation Mode
SEIF
Session interrupt
Host or device mode
DISCIF
Disconnect interrupt flag
Host Mode
IDPSC
ID pin status change
Host or device mode