GD32W51x User Manual
834
2. Program USBFS_GUSBCS
register according to application’s demand, such as: the
operation mode (host, device or OTG) and some parameters of OTG and USB protocols.
3.
Program USBFS_GCCFG register according to application’s demand.
4. Program USBFS_GRFLEN, USBFS_HNPTFLEN_DIEP0TFLEN, USBFS_DIEPxTFLEN
register to configure the data FIFOs according to application’s demand.
5. Program USBFS_GINTEN register to enable Mode Fault, Suspend, SOF, Enumeration
Done and USB Reset interrupt and then, set GINTEN bit in USBFS_GAHBCS register to
enable global interrupt.
6.
Program USBFS_DCFG register according to application’s demand, such as the device
address, etc.
7. After the device is connected to a host, the host will perform port reset on USB bus and
this will trigger the RST interrupt in USBFS_GINTF regis ter.
8. Wait for ENUMF interrupt in USBFS_GINTF register.
Endpoint initialization and enable sequence
1. Program USBFS_DIEPxCTL or USBFS_DOEPxCTL register with desired transfer type,
packet size, etc.
2. Program USBFS_DIEPINTEN or USBFS_DOEPINTEN register. Set the desired interrupt
enable bits.
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 singl
e 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