Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
601
/
631
and SW_BUF indicates the buffer currently being used by the application on the microcontroller. The definitions of
DATTOG and SW_BUF are shown in Table 26-1 shown. A unidirectional endpoint using the double buffer
mechanism only needs to use one USB_EPn register.
Table 26-1 DATTOG and SW_BUF definitions
Buffer flag
Sending endpoint
Receiving endpoint
DATTOG
DATTOG_TX
(Bit 6 of the USB_EPn register)
DATTOG_RX
(Bit 14 of the USB_EPn register)
SW_BUF
Bit 14 of the USB_EPn register
Bit 6 of the USB_EPn register
As shown in Figure 26-3, when an endpoint uses the double buffer mechanism, all four buffer description table entries
of the endpoint will be used. DATTOG and SW_BUF are responsible for flow control. When a transfer is complete,
the USB hardware toggles the DATTOG bit; when the application on the microcontroller has finished processing the
data, the software toggles SW_BUF bit. After the first transfer starts, in the subsequent transfer process, if the values
of DATTOG and SW_BUF are equal, a buffer access conflict occurs between the USB module and the application,
the transfer is paused, and a NAK handshake packet is sent to the host; when the values of DATTOG and SW_BUF
are not equal, normal USB communication can be performed.
Table 26-2 How to use double buffering
Endpoint type
DATTOG
SW_BUF
Buffer used by the USB module
Buffers used by the application
IN Endpoint
0
1
ADDRn_TX_0/CNTn_TX_0
ADDRn_TX_1/CNTn_TX_1
1
0
ADDRn_TX_1/CNTn_TX_1
ADDRn_TX_0/CNTn_TX_0
0
0
Endpoint is in NAK state
ADDRn_TX_0/CNTn_TX_0
1
1
Endpoint is in NAK state
ADDRn_TX_1/CNTn_TX_1
OUT Endpoint
0
1
ADDRn_RX_0/CNTn_RX_0
ADDRn_RX_1/CNTn_RX_1
1
0
ADDRn_RX_1/CNTn_RX_1
ADDRn_RX_0/CNTn_RX_0
0
0
Endpoint is in NAK state
ADDRn_RX_0/CNTn_RX_0
1
1
Endpoint is in NAK state
ADDRn_RX_1/CNTn_RX_1
Note:
1
、
The double-buffered bulk endpoint will only set the endpoint to the NAK state when there is a buffer access
conflict, and will not set the endpoint to the NAK state after each correct transmission is completed.
Double-buffered endpoint usage
If you want to use double-buffered bulk endpoints, you can set them up as follows:
Set USB_EPn.EP_TYPE = 00, define the endpoint as a bulk endpoint
Set USB_EPn.EP_KIND = 1, define endpoint as double buffer endpoint
As shown in Figure 26-3, when double-buffered bulk endpoint 3 performs data transmission in the OUT direction,
assuming DATTOG = 1 and SW_BUF = 0, it means that the application can process the data in buffer0 corresponding
to ADDR3_RX_0/CNT3_RX_0, after receiving the data from the USB bus, the USB module fills the data into the
buffer1 corresponding to ADDR3_RX_1/CNT3_RX_1. When a transaction transfer on the USB bus is completed,
the hardware will toggle DATTOG = 0. If the application has not finished processing the data in buffer0