
AT32F435/437
Series Reference Manual
2022.11.11
Page 425
Rev 2.03
(3) Internal storage space allocation
Table 21-3 OTGFS internal storage space allocation
FIFO Name
Data SRAM Size
Receive FIFO
rx_fifo_size
Non-periodic transmit FIFO
tx_fifo_size[0]
Periodic transmit FIFO
tx_fifo_size[1]
Configure the following registers according to the above mentioned:
1. OTGFS receive FIFO size register (OTGFS_GRXFSIZ)
OTGFS_GRXFSIZ.RXFDEP = rx_fifo_size
2. OTGFS Non-periodic TX FIFO size register (OTGFS_GNPTXFSIZ)
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.
21.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.
21.5.3 OTGFS host mode
21.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