USB on-the-go full-speed/high-speed (OTG_FS/OTG_HS) RM0390
1238/1328 RM0390 Rev 4
31.16.6 Device programming model
Endpoint initialization on USB reset
1. Set the NAK bit for all OUT endpoints
– SNAK = 1 in OTG_DOEPCTLx (for all OUT endpoints)
2. Unmask the following interrupt bits
– INEP0 = 1 in OTG_DAINTMSK (control 0 IN endpoint)
– OUTEP0 = 1 in OTG_DAINTMSK (control 0 OUT endpoint)
– STUPM = 1 in OTG_DOEPMSK
– XFRCM = 1 in OTG_DOEPMSK
– XFRCM = 1 in OTG_DIEPMSK
– TOM = 1 in OTG_DIEPMSK
3. Set up the data FIFO RAM for each of the FIFOs
– Program the OTG_GRXFSIZ register, to be able to receive control OUT data and
setup data. If thresholding is not enabled, at a minimum, this must be equal to 1
max packet size of control endpoint 0 + 2 words (for the status of the control OUT
data packet) + 10 words (for setup packets).
– Program the OTG_DIEPTXF0 register (depending on the FIFO number chosen) to
be able to transmit control IN data. At a minimum, this must be equal to 1 max
packet size of control endpoint 0.
4. Program the following fields in the endpoint-specific registers for control OUT endpoint
0 to receive a SETUP packet
– STUPCNT = 3 in OTG_DOEPTSIZ0 (to receive up to 3 back-to-back SETUP
packets)
5. For USB OTG_HS in DMA mode, the OTG_DOEPDMA0 register should have a valid
memory address to store any SETUP packets received.
At this point, all initialization required to receive SETUP packets is done.
Endpoint initialization on enumeration completion
1. On the Enumeration Done interrupt (ENUMDNE in OTG_GINTSTS), read the
OTG_DSTS register to determine the enumeration speed.
2. Program the MPSIZ field in OTG_DIEPCTL0 to set the maximum packet size. This
step configures control endpoint 0. The maximum packet size for a control endpoint
depends on the enumeration speed.
3. For USB OTG_HS in DMA mode, program the OTG_DOEPCTL0 register to enable
control OUT endpoint 0, to receive a SETUP packet.
At this point, the device is ready to receive SOF packets and is configured to perform control
transfers on control endpoint 0.
Endpoint initialization on SetAddress command
This section describes what the application must do when it receives a SetAddress
command in a SETUP packet.
1. Program the OTG_DCFG register with the device address received in the SetAddress
command
2. Program the core to send out a status IN packet