- No category
advertisement
USB device library UM1021
6.3.6
6.3.7
Using the multi-packet feature
To transmit data, the DCD_EP_Tx () function is called and to receive data
DCD_EP_PrepareRx()
is called, an with unlimited data length. Internally, the USB OTG core checks the available space in the FIFO and processes the transfer, respecting the endpoint size. For example, if the endpoint size is configured to work with 64 bytes of data and the user wants to transmit / receive N bytes of data, the USB core sends / receives several packets of 64 bytes each.
USB control functions
User applications can benefit from a few other USB functions included in a USB device.
Device reset
When the device receives a reset signal from the USB, the library resets and initializes the application on both software and hardware.
This function is part of the interrupt routine. Interrupt routine restrictions apply.
Device suspend
When the device detects a suspend condition on the USB, the library stops all the operations and puts the system to suspend state (if low power mode is enabled by in the
usb_conf.h file).
Device resume
When the device detects a resume signal on the USB, the library restores the USB core clock and puts the system to idle state (if low power mode is enabled by in the usb_conf.h file).
6.3.8 FIFO customization
In order to use a new endpoint or change the endpoint already used in the application, the user has to take care of two things:
1.
Endpoint initialization: this phase is done generally in the usbd_class_core layer through the following function: uint32_t DCD_EP_Open (USB_OTG_CORE_HANDLE *pdev , uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
The ep_addr should hold the endpoint address, note the endpoint direction is identified by the MSB bit (ie "0x80| ep" index for ep IN endpoint) and the ep_mps holds the max packet size of the endpoints.
2. The FIFO configuration done in the usb_core.c file in the usb low level driver , the FIFO configuration could be modified by the user through the usb_conf.h file.
#ifdef USB_OTG_FS_CORE
#define RX_FIFO_FS_SIZE128
#define TX0_FIFO_FS_SIZE64
#define TX1_FIFO_FS_SIZE128
#define TX2_FIFO_FS_SIZE0
30/107 Doc ID 18153 Rev 3
UM1021
Note:
USB device library
#define TX3_FIFO_FS_SIZE0
#endif
#ifdef USB_OTG_HS_CORE
#define RX_FIFO_HS_SIZE512
#define TX0_FIFO_HS_SIZE128
#define TX1_FIFO_HS_SIZE384
#define TX2_FIFO_HS_SIZE0
#define TX3_FIFO_HS_SIZE0
#define TX4_FIFO_HS_SIZE0
#define TX5_FIFO_HS_SIZE0
#endif
The configuration of the FIFO is described in detail in reference manuals RM0033 and
RM0008. The Rx and the TXs FIFOs can be calculated as follows:
1.
Receive data FIFO size = RAM for setup packets + Data Out endpoint control information + Data Out packets + Miscellaneous
Space = ONE 32-bit word
– RAM for setup packets = 10
– Data Out endpoint control information = 1 space (one space for status information written to the FIFO along with each received packet).
– Data Out packets = (largest packet size / 4) + 1 space (MINIMUM to receive packets) OR Data Out packets = at least 2*(largest packet size / 4) + 1 space (if high-bandwidth endpoint is enabled or multiple isochronous endpoints)
– Miscellaneous = 1 space per Data Out endpoint (one space for transfer complete status information also pushed to the FIFO with each endpoint's last packet)
2. MINIMUM RAM space required for each Data In endpoint Tx FIFO = MAX packet size for that particular Data In endpoint. More space allocated in the Data In endpoint Tx
FIFO results in a better performance on the USB and can hide latencies on the AHB.
3. Txn minimum size = 16 words. (where, n is the Transmit FIFO index).
4. When a Tx FIFO is not used, the Configuration should be as follows:
Case 1: n > m and Txn is not used (where, n,m are the Transmit FIFO indexes)
– Txm can use the space allocated for Txn.
Case 2: n < m and Txn is not used (where, n,m are the Transmit FIFO indexes)
– Txn should be configured with the minimum space of 16 words
5. The FIFO is used optimally when used TxFIFOs are allocated in the top of the FIFO.
For example, use EP1 and EP2 as IN instead of EP1 and EP3 as the IN ones.
The total FIFO size for the used USB OTG core: for the USB OTG FS core, the total
FIFO size is 320 * 32 bits while for the USB OTG HS core, the total FIFO size is 1024 *
32 bits.
Example
If the application uses 1 IN endpoint for control with MPS = 64 Bytes, 1 OUT Endpoint for
Control with MPS = 64 Bytes and 1 IN Bulk endpoint for the class with MPS = 512 Bytes.
Doc ID 18153 Rev 3 31/107
advertisement
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
advertisement
Table of contents
- 8 Reference information
- 8 Glossary
- 9 USB host and device library overview
- 9 Main features
- 10 USB host and device library folder structure
- 11 USB OTG core
- 11 USB OTG full speed core
- 11 OTG_FS interface main features
- 11 USB OTG high speed core
- 13 USB OTG low level driver
- 13 USB OTG low level driver architecture
- 13 USB OTG low level driver files
- 14 USB OTG low level driver configuration
- 15 USB OTG driver programming manual
- 15 Low level driver structures
- 15 Programming considerations when using internal DMA
- 17 Selecting USB physical interface
- 17 Programming device drivers
- 20 Programming host drivers
- 23 USB device library
- 23 USB device library overview
- 24 USB device library files
- 24 USB device library description
- 24 USB device library flow
- 27 USB device library process
- 28 USB device data flow
- 29 USB device library configuration
- 29 USB data transfer handling
- 30 Using the multi-packet feature
- 30 USB control functions
- 30 FIFO size customization
- 32 USB device library functions
- 35 USB device class interface
- 36 USB device user interface
- 38 USB device classes
- 39 HID class
- 40 Mass storage class
- 45 Device firmware upgrade (DFU) class
- 52 Audio class
- 56 Communication device class (CDC)
- 61 Adding a custom class
- 62 Application layer description
- 63 Starting the USB device library
- 64 USB device examples
- 64 USB mass storage device example
- 65 USB human interface device example
- 67 Dual core USB device example
- 68 USB device firmware upgrade example
- 70 USB virtual com port (VCP) device example
- 73 USB audio device example
- 74 Known limitations
- 75 USB host library
- 75 Overview
- 76 USB host library files
- 77 USB host library description
- 77 Host core state machine
- 78 Device enumeration
- 79 Control transfer state machine
- 79 USB I/O request module
- 79 Host channel control module
- 79 USB host library configuration
- 79 USB host library functions
- 81 USB host class interface
- 81 USB host classes
- 81 Mass storage class
- 85 HID class
- 88 USB host user interface
- 88 Library user API
- 88 User callback functions
- 88 Class callback functions
- 92 Application layer description
- 93 Starting the USB host library
- 94 USB host examples
- 95 USB mass storage host example
- 98 USB HID Host example
- 99 USB dual core host example
- 100 USB manual dual role device example
- 102 Frequently-asked questions
- 105 Troubleshooting
- 106 Revision history