AT32F425
Series Reference Manual
2022.03.30
Page 349
Ver 2.01
20.5.3.2 OTGFS channel initialization
To communicate with the device, the application must enable and initialize at least one channel according
to the following steps:
1. Unmask the following interrupts by setting the OTGFS_GINTMSK register:
Non-periodic transmit FIFO empty for OUT transfers
Non-periodic transmit FIFO half empty for OUT transfers
2.
Unmask the interrupts of the selected channels by setting the OTGFS_HAINTMSK register
3.
Unmask the transfer-related interrupts in the host channel interrupt register by setting the
OTGFS_HCINTMSKx register
4.
Configure the total transfer size (in bytes), and the expected number of the packets (including short
packets) for the OTGFS_HCTSIZx register of the selected channel. The application must configure
the PID bit according to the initial data PID (it is the PID on the first OUT transfer, or to be received
from the first IN transfer)
5.
Configure the transfer size to ensure that the transfer size of the channel is a multiple of the largest
packet size
6.
Configure the OTGFS_HCCHARx register of the selected channel according to the device endpoint
characteristcs such as type, speed and direction (the channel cannot be enabled by setting the
enable bit until the application is ready for packet transfer or reception)
20.5.3.3 Halting a channel
The application can disable a channel by writing 0x1 to the CHDIS and CHENA bits in the
OTGFS_HCCHARx register. This enables the host to refresh the summited requests (if any) and
generates a channel halted interrupt. The application cannot re-allocate channels for other transactions
until an interrupt is genearated in the OTGFS_HCINTx register (CHHLTD bit). Those transactions that
have already been started on the USB line are not interrupted by the host.
Before disabling a channel, the application must ensure that there is at least one free space available in
the non-periodic request queue (when disabling a non-perioid channel) or the periodic request queue
(when disabling a periodic channel). The application can refresh the submitted requests when the
request queue is full (before disabling the channel) by setting CHDIS=0x1, and CHENA=0 in the
OTGFS_HCCHARx register.
When there is a transaction input in the request queue, the controller will trigger a RXFLVL interrupt. The
application must generate a channel halted interrupt through the OTGFS_GRXSTSP register.
The application is expected to abort a channel on any of the following conditions:
When an interrupt (XFERC bit) is received in the OTGFS_HCINTx register during a non-periodic
IN transfer
When an STALL , XACTERR , BBLERR or DTGLERR interrupt in the OTGFS_HCINTx register
is received for an IN or OUT channel
When a DISCONINT (device disconnected) interrupt event is received in the OTGFS_GINTSTS
register, the application must check the PRTCONSTS bit in the OTGFS_HPRT register. This is
because when the device is disconnected with the host, the PRTCONSTS bit will be reset in the
OTGFS_HPRT register. The application must initiate a software reset to ensure that all channels
have been cleared. Once the device is reconnected, the host must start a USB reset.
When the application needs to abort a transfer before normal completion
20.5.3.4 Queue depth
Up to 8 interrupt and synchronous transfer requests are supported in the periodic hardware transfer
request queue; while up to 8 control and bulk transfer requests are allowed in the non-periodic hardwre
transfer request queue.
Writing the transmit FIFO
shows the flow chart of writing the transmit FIFO. The OTGFS host automatically writes a
request (OUT request) to the periodic/non-periodic request queue when writing the last one DWORD
packet. The application must ensure that at least one free space is available in the periodic/non-periodic