GD32VF103 User Manual
472
Channel initialization and enable sequence
1. Program USBFS_HCHxCTL registers with desired transfer type, direction, packet size,
etc. Ensure that CEN and CDIS bits keep cleared during configuration.
2. Program USBFS_HCHxINTEN register. Set the desired interrupt enable bits.
3. Program USBFS_HCHxLEN 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 OUT channel: 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_HCHxCTL register, and the last packet
’s size is
calculated based on PCNT, TLEN and MPL. If software want s to send out a zero-length
packet, it should program TLEN=0, PCNT=1.
For IN channel: Because the application doesn
’t know the actual received data size
before the IN transaction finishes, TLEN can be set to a maximum possible value
supported by Rx FIFO.
4. Set CEN bit in USBFS_HCHxCTL register to enable the channel.
Channel disable sequence
Software can disable the channel by setting both CEN and CDIS bits at the same time.
USBFS will generate a channel disable request entry in request queue after the register
setting operation. When the request entry reaches the top of request queue, it is processed
by USBFS immediately:
For OUT channels, the specified channel will be disabled immediately. Then, a CH flag will
be generated and the CEN and CDIS bits will be cleared by USBFS.
For IN channels, USBFS pushes a channel disable status entry into Rx FIFO. Software should
then handle the Rx FIFO not empty event: read and pop this status entry, then, a CH flag will
be generated and the CEN and CDIS bits will be cleared.
IN transfers operation sequence
1. Initialize USBFS global registers.
2. Initialize the channel.
3. Enable the channel.
4. After the IN channel is enabled by software, USBFS generates an Rx request entry in the
corresponding request queue.
5. When the Rx request entry reaches the top of the request queue, USBFS begins to
process this request entry. If bus time for the IN transaction indicated by the request entry
is enough, USBFS starts the IN transaction on USB bus.
6. If the IN transaction finishes successfully (ACK handshake received), USBFS pushes the