AT32F425
Series Reference Manual
2022.03.30
Page 364
Ver 2.01
}
else if (CHHLTD)
{
Mask CHHLTD
De-allocate Channel
}
20.5.4 OTGFS device mode
20.5.4.1 Device initialization
The application must perform the following steps to initialize the controller during power-on or after
switching a mode from host to device:
1. Program the following fields in the OTGFS_DCFG register
Device speed
Non-zero-length status OUT handshake
Periodic frame interval
2. Clear the SFTDISCON bit in the OTGFS_DCTL register. The controller will start connection after
clearing this bit
3. Program the OTGFS_GINTMSK register to unmask the following interrupts:
USB reset
Enumeration done
Early suspend
USB suspend
SOF
4. Wait for the USBRESET interrupt in the OTGFS_GINTSTS register. It indicates that a reset signal has
been detected on the USB (lasting for about 10ms). Upon receiving this interrupt, the application must
follow the steps defined in USB initialization on USB reset.
5. Wait for the ENUMDONE interrupt in the OTGFS_GINTSTS register. It indicates the end of USB reset.
Upon receiving this interrupt, the application must read the OTGFS_DSTS register to determine the
enumeration speed and perform the steps defined in Endpoint initialization on enumeration completion.
At this time, the device is ready to accept SOF packets and perform control transfers on control endpoint
0.
20.5.4.2 Endpoint initialization on USB reset
This section describes the operations required for the application to perform when a USB reset signal is
detected:
1. Set the NAB bit for all OUT endpoints
OTGFS_DOEPCTLx.SNAK = 0x1(for all OUT endpoints)
2. Unmask the following interrupt bits
OTGFS_DAINTMSK.INEP0 = 0x1(control IN endpoint 0)
OTGFS_DAINTMSK.OUTEP0 = 0x1(control OUT endpoint 0)
OTGFS_DOEPMSK.SETUP = 0x1
OTGFS_DOEPMSK.XFERC = 0x1
OTGFS_DIEPMSK.XFERC = 0x1
OTGFS_DIEPMSK.TIMEOUT = 0x1
3. To receive/transmit data, the device must peform Device initialization steps to initialize registers
4. Allocate SRAM for each endpoint
Program the OTGFS_GRXFSIZ register to be able to receive control OUT data and SETUP data.
If the allocated SRAM is equal to at least 1 largest-packet-size of control endpoint 0 + 2 DWORDs
(for the status of the control OUT data packet) +10 DWORDs (for setup packets)
Program the OTGFS_DIEPTXF0 register to be able to transmit control IN data. The allocated
SRAM is equal to at least 1 largest-packet-size of control endpoint 0
5. Reset the device addres in the device configuration register
6. Program the following fields in the endpoint-specific registers to ensure that control OUT endpoint 0
is able to receive a SETUP packet