AT32WB415
Series Reference Manual
2022.04.13
Page 295
Ver 2.00
OTGFS_GNPTXFSIZ.NPTXFDEP = tx_fifo_size[0]
OTGFS_GNPTXFSIZ. NPTXFSTADDR = rx_fifo_size
3. OTGFS host periodic transmit FIFO size register (OTGFS_HPTXFSIZ)
OTGFS_HPTXFSIZ.PTXFSIZE = tx_fifo_size[1]
OTGFS_HPTXFSIZ.PTXFSTADDR = OTGFS_GNPTXFSIZ.NPTXF tx_fifo_size[0]
4. After SRAM allocation, refresh transmit FIFO and receive FIFO to ensure normal FIFO running.
OTGFS_GRSTCTL.TXFNUM = 0x10
OTGFS_GRSTCTL.TXFFLSH = 0x1
OTGFS_GRSTCTL.RXFFLSH = 0x1
The application cannot perform other operations on the controller until the TXFFLSH and
RXFFLSH bits are cleared.
20.5.2.3 Refresh controller transmit FIFO
The application refreshes all transmit FIFOs through the TXFFLSH bit in the OTGFS_GRSTCTL register:
Check whether GINNAKEFF=0 or not in the OTGFS_GINTSTS register. If this bit has been
cleared, write 0x1 to the OTGFS_DCTL.SGNPINNAK register. When the NACK valid interrupt is
set, it means that the controller does not read FIFO.
Wait until GINNAKEFF = 0x1 in the OTGFS_GINTSTS register, indicating that the NAK
configuration has taken effect for all IN endpoints.
Poll the OTGFS_GRSTCTL register and wait until AHBIDLE=1. AHBIDLE = H indicates that the
controller does not write the FIFO.
Confirm whether TXFFLSH = 0x0 or not in the OTGFS_GRSTCTL register. If TXFFLSH is cleared,
write the transmit FIFO number to be refreshed into the OTGFS_GRSTCTL.TXFNUM register.
Set TXFFLSH = 0x1 in the OTGFS_GRSTCTL register, and wait until it is cleared.
Set the CGNPINNAK bit in the OTGFS_DCTL register.
20.5.3 OTGFS host mode
In host mode, an external voltage pump is required to supply VBUS continuously, for the controller is
uable to provide 5V for VBUS internally.
20.5.3.1 Host initialization
The following steps must be respected to initialize the controller:
1.
Unmask interrupt through the PRTINTMSK bit in the OTGFS_GINTMSK register
2.
Program the OTGFS_HCFG register
3.
Set PRTPWR = 0x1 in the OTGFS_HPRT register to drive VBUS supply on the USB
4.
Wait until that the PRTCONDETbit is set in the OTGFS_HPRT0 register, indicating that the device
is connected to the port
5.
Set PRTRST = 0x1 in the OTGFS_HPRT register to issue a reset operation
6.
Wait for at least 10 ms to ensure the completion of the reset
7.
Set PRTRST = 0x0 in the OTGFS_HPRT register
8.
Wait for the interrupt (PRTENCHNG bit in the OTGFS_HPRT register)
9.
Read the PRTSPD bit in the OTGFS_HPRT register to get the enumeration speed
10.
Configure the HFIR register according to the selected PHY clock value
11.
Select the size of the receive FIFO by setting the OTGFS_GRXFSIZ register
12.
Select the start address and size of the non-periodic transmit FIFO by setting the
OTGFS_GNPTXFSIZ register
13.
Select the start address and size of the periodic transmit FIFO by setting the OTGFS_HPTXFSIZ
register
To communicate with the device, the application must enable and initialize at least one channel according
to OTGFS channel initialization requirements.