Need help Interpretting STM32F070 USB User Guide
The below paragraph to me is almost incoherient. I don't have a usb protocol analyser so its important I get this right (From page 684 of the RM0350 user guide):
OUT and SETUP packets (data reception)
"These two tokens are handled by the USB peripheral more or less in the same way; the
differences in the handling of SETUP packets are detailed in the following paragraph about
control transfers. When receiving an OUT/SETUP PID, if the address matches a valid
endpoint, the USB peripheral accesses the contents of the ADDRn_RX and COUNTn_RX
locations inside the buffer descriptor table entry related to the addressed endpoint. The
content of the ADDRn_RX is stored directly in its internal register ADDR. While COUNT is
now reset and the values of BL_SIZE and NUM_BLOCK bit fields, which are read within
COUNTn_RX content are used to initialize BUF_COUNT, an internal 16 bit counter, which is
used to check the buffer overrun condition (all these internal registers are not accessible by
software). Data bytes subsequently received by the USB peripheral are packed in half-
words (the first byte received is stored as least significant byte) and then transferred to the
packet buffer starting from the address contained in the internal ADDR register while
BUF_COUNT is decremented and COUNT is incremented at each byte transfer. When the
end of DATA packet is detected, the correctness of the received CRC is tested and only if no
errors occurred during the reception, an ACK handshake packet is sent back to the
transmitting host."
-
For definitions I'm defining:
Packet Memory Area (PMA)
This term is defined in the user guide but then not used everywhere that is relevant.
Allocated Endpoint Buffer Memory Region (AEBMR)
The contents of the receive buffer in the region defined by ADDRn_RX and COUNTn_RX.
-
My interpretation of the paragraph
"When receiving an OUT/SETUP PID, if the address matches a valid endpoint, the USB
peripheral accesses the contents of the ADDRn_RX and COUNTn_RX locations inside the
buffer descriptor table entry related to the addressed endpoint."
When the device receives a Packet ID (PID) that refers to a valid endpoint, the USB peripheral hardware accesses the contents of the PMA (in the region defined by ADDRn_RX and COUNTn_RX).
"The content of the ADDRn_RX is stored directly in its internal register ADDR. While COUNT is
now reset and the values of BL_SIZE and NUM_BLOCK bit fields, which are read within
COUNTn_RX content are used to initialize BUF_COUNT, an internal 16 bit counter, which is
used to check the buffer overrun condition (all these internal registers are not accessible by
software)."
The inaccessible internal buffer is copied into AEBMR automatically.
COUNT, BL_SIZE and NUM_BLOCK fields are reset.
COUNTn_RX is used to initialise an internal counter (BUF_COUNT) to prevent buffer overrun conditions.
"Data bytes subsequently received by the USB peripheral are packed in half-words
(the first byte received is stored as least significant byte) and then transferred to the
packet buffer starting from the address contained in the internal ADDR register while
BUF_COUNT is decremented and COUNT is incremented at each byte transfer."
Data is stored inside the AEBMR. Data is packed in half-words (16 bits):
For example if four bytes 0x01 to 0x04 were received in ascending order:
Address Data
0x0000 0x0201
0x0002 0x0403
And in memory starting at address 0x0000:
0x02010403
This requires reordering of the half words before processing data in a byte stream:
0x01020304.
"When the end of DATA packet is detected, the correctness of the received CRC is tested
and only if no errors occurred during the reception, an ACK handshake packet is sent back to the transmitting host."
CRC is sent at the end of the data packet.
If there are no errors, ACK is sent back to the transmitting host.
