English
Language : 

UM0463 Datasheet, PDF (14/30 Pages) STMicroelectronics – ST7 full-speed USB library
The USB state machine of the control endpoint
UM0463
3.4.3
big chunk of data (larger than the MCU RAM size) located in an external memory, then the
data stream has to be split into small pieces and read into RAM piece by piece.
In the USER_USB_Setup (), the user code should assign the variable vUSB_DataToCopy
as NULL (char *0) and the variable vUSB_length as the size of the data stream. Then, when
the library is going to send a data packet of the data IN stage, it calls a callback function
USER_USB_CopydataIN (unsigned char CopyLength). In this function, the user code
should copy CopyLength bytes of data from its own buffer to the endpoint DMA buffer
EP0_IN. The variable vUSB_offset indicates where to start copying the data.
In this way, the user code can generate the data stream, for example reports of GET
REPORT request, in the DMA buffer directly and dynamically.
Data OUT stage
When a data OUT stage is necessary, the user code should assign the number of bytes that
is going to receive to the variable vUSB_length in the USER_USB_Setup () and return to the
caller of USER_USB_Setup (). Every time the library receives a data packet, it then calls
callback USER_USB_CopydataOUT (unsigned char CopyLength). In the function
USER_USB_CopydataOUT (), the user code has to copy the data to its own buffer from the
endpoint DMA buffer EP0_OUT. The variable vUSB_offset indicates the offset of this data
packet in the data stream. Of course, the user code can process the received data in the
endpoint buffer EP0_OUT directly if the data stream fits in the buffer.
Before returning to the caller of USER_USB_CopydataOUT (), the library will not go on to
receive the next data packet or to the status stage. Please do not stay in the function
USER_USB_CopydataOUT () for a long time as it will slow down the performance of the
USB system.
Status stage
The status stage of a control endpoint identifies the end of a SETUP transaction. To the user
application, the status stage means that all data bytes have been sent/received. It is time to
release the data buffer and prepare another data stream for the next data IN stage or to
process the received data and prepare a new buffer for the next data OUT stage.
The library calls callback function USER_USB_Status_In() after the host acknowledges a
status IN stage and calls callback function USER_USB_Status_Out() after it acknowledges
a status OUT stage. In these two callback functions, the user code can call RequestError() if
the request is an invalid request or there is any error in the data stage (for example received
invalid data or failed to collect data to send).
3.5
Processing of standard requests
After the SETUP packet is copied into sUSB_vSetup, the request and its parameters are
parsed. Standard requests defined in Section 3.3 are handled in the library with less user
code intervention. The following sections will discuss how the library processes each
standard request and when the user code will be involved.
14/30