
GD32F403xx User Manual
645
Host mode
Global register initialization sequence
1.
Program USBFS_GAHBCS register according to application’s demand, such as the
TxFIFO’s empty threshold, etc. GINTEN bit should be kept cleared at this time.
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. Prog
ram USBFS_GCCFG register according to application’s demand.
4. Program USBFS_GRFLEN, USBFS_HNPTFLEN_DIEP0TFLEN and USBFS_HPTFLEN
register to configure the data FIFOs according to application’s demand.
5. Program USBFS_GINTEN register to enable Mode Fault and Host Port interrupt and set
GINTEN bit in USBFS_GAHBCS register to enable global interrupt.
6. Program USBFS_HPCS register and set PP bit.
7.
Wait for a device’s connection, and once a device is connected, the connection interrupt
PCD in USBFS_HPCS register will be triggered. Then set PRST bit to perf orm a port
reset. Wait f or at least 10ms and then clear PRST bit.
8. Wait PEDC interrupt in USBFS_HPCS register and then read PE bit to ensure that the
port is successfully enabled. Read PS [1:0] bits to get the connected
device’s speed and
then program USBFS_HFT register to change the SOF interval if needed.
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 transf er and
TLEN is the total byte 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
f ormer 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 wants 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
bef ore the IN transaction f inishing, TLEN could 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