AT32F425
Series Reference Manual
2022.03.30
Page 376
Ver 2.01
endpoint of the frame before the frame to be transmitted.
For example, to send data on the frame n, enable the endpoint of the frame n-1. Additionally, the OTGFS
controller schedules the synchronous transfers by setting Even/Odd frame bits.
【
Synchronous
IN tramsfer interrupt
】
The following interrupts must be processed to ensure successful scheduling of the synchronous
transfers.
XFERC interrupt in the OTGFS_DIEPINTx register (for endpoints)
OTG INCOMPISOIN interrupt in the OTGFS_GINTSTS register (for global interrupts)
【
Handling synchronous IN transfers
】
The following steps must be performed to handle a synchroniys IN transfer:
1. Unmask the incompISOOUT interrupt in the OTGFS_GINTSTS register by setting the
INCOMISOINMSK interrupt bit in the OTGFS_GINTMSK register
2. Unmask the XFERC interrupt in the OTGFS_DIEPINTx register by setting the XFERCMSK bit in the
OTGFS_DIEPMSK register
3. Enable synchronous endpoints with the following steps:
Program the OTGFS_DIEPTSIZx register
OTGFS_DIEPTSIZx.XFERSIZE= n * OTGFS_DIEPCTLx.MPS + sp, where 0 <= n <= 3 and 0 <=
sp <OTGFS_DIEPCTLx.MPS. When the transfer size in a frame is less than that of the MPS bit in the
OTGFS_DIEPCTLx register, n=0; When the transfer size in a frame is a multiple of that of the MPS bit
in the OTGFS_DIEPCTLx register, sp=0.
OTGFS_DIEPTSIZx.PKTCNT = 0x1
The MC bit in the OTGFS_DIEPTSIZx register is set the same value as that of the PKTCNT bit in
the OTGFS_DIEPTSIZx register.
Program the OTGFS_DIEPCTLx register
Read the OTGFS_DSTS register to determine the current frame number
Program the OTGFS_DIEPCTLx with the maximum packet size (MPS bit)
Set USBACTEP = 0x1 in the OTGFS_DIEPCTLx register
Set EPTYPE = 0x1 in the OTGFS_DIEPCTLx register, marking synchornization
Set the FIFO number of the endpoint through the TXFNUM bit in the OTGFS_DIEPCTLx register
Set CNAK = 0x1 in the OTGFS_DIEPCTLx register
If.SOFFN[0] = 0x0 in OTGFS_DSTS, then SETEVENFR = 0x1 in OTGFS_DIEPCTLx (otherwise,
SETEVENFR = 0x1 in OTGFS_DIEPCTLx)
If SOFFN[0] = 0x1 in OTGFS_DSTS, then SETODDFR = 0x1 in OTGFS_DIEPCTLx (otherwise,
SETODDFR = 0x0 in OTGFS_DIEPCTLx)
Set EPENA = 0x1 in OTGFS_DIEPCTLx
4. Write endpoint data to the corresponding transmit FIFO
For example, write address ranges are as follows:
EP1 corresponding to 0x2000 - 0x2FFC
EP2 corresponding to 0x3000 - 0x3FFC
EP3 corresponding to 0x3000 - 0x3FFC
...
5. Wait for interrupts
When an interrupt is generated (XFERC bit in OTGFS_DIEPINTx register), clear the XFERC
interrupt; For the following transaction, repeat step 3-5 until the completion of data transfers.
When an interrupt is generated (INCOMPISOIN bit in OTGFS_GINTSTS register), clear the
INCOMPISOIN interrupt; For any synchronous IN endpoint, when Odd/Even bits match the current
frame number bit 0, and when the endpoint remains enabled, the controller generates an interrupt at
the end of the frame. This interrupt is generated on one of the following conditions:
(1)There is no token in a frame
(2) Late data write to the receive FIFO. An IN token has arrived before the completion of data write
(
3
)
IN token error