|
![]() USB
![]() C8051F340 USB_Bulk example question
|
| next newest topic | next oldest topic |
| Author | Topic: C8051F340 USB_Bulk example question |
|
grandnie New Member |
Hello,I come from china. I have one question about the USB_Bulk example for the C8051F340. The example code is written: // Check for ACK packet after writing 8 pkts. question : when finished to transfer 512 BYTE(8 pkts) data from the Host to the Device, We must be check for ACK packet??? Thanks. IP: Logged |
|
Tsuneo Member |
Ah, confusing enough. The "PACKET" (MAX_PACKET_SIZE_WRITE) and "ACK" on this code have no direct relation to the USB protocol. These terms belong to the original protocol just for this application, carried over USB. To make it more USB savvy, the "PACKET" should be called as transfer. "ACK" is acknowledge transfer.
1) Transfer - transaction - packet Transfer is the greatest unit of communication structure on USB. The hardware parts, the host controller and the USB engine (SIE: Serial Interface Engine) on the MCU, interpret transaction into packets, like IN-DATA-ACK or OUT-DATA-ACK. Host app handles transfer directly, and firmware does in the split shape, a sequence of transactions. For example, suppose that a host app sends 200 bytes of data. It is sent by single WriteFile (or equivalent call) to the device driver. The device driver and the host controller splits it into transactions, according to the wMaxPacketSize of the endpoint. When wMaxPacketSize = 64, the firmware sees this sequence of transactions, as 200 bytes transfer. 64, 64, 64, 8 In the opposite direction, also, the reverse process is done; the firmware sends a sequence of transactions, they are combined together into a single block, and handed to the host app as a single transfer over single ReadFile(). In this way, any size of transfer is carried over USB, even if it grows up to MBytes.
- When error occurs on the transfer, ReadFile and WriteFile returns error, either directly (synchronous call), or indirectly (asynchronous call). When these APIs succeed, the transfers succeed without error. - On the coding of host app, you don't need to be aware of the packet payload size (wMaxPacketSize). It is handled automatically by the host controller.
USB spec defines the end of bulk and interrupt transfer as follows, a) Has transferred exactly the amount of data expected a) Expected transfer size For example, these parameters of ReadFile and WriteFile mean the expected transfer size. On the other hand, the firmware doesn't know the expected size, b) Short packet Using short packet, the firmware can cut off the transfer, before the transfer size reaches to the expected size. When the transfer size is just the multiple of wMaxPacketSize, ZLP is appended to the transfer to stop the transfer in halfway. For example, the host app requests 200 bytes transfer, But the firmware returns 128 bytes (wMaxPacketSize = 64), ZLP is appended because the firmware cuts off the transfer. However, the host app requests just 128 bytes here, no ZLP is appended, because it matches to the expected size. nNumberOfBytesToRead = 128; Please note, ZLP is seen just for IN transfers, not for OUT transfers, because host always sends just the expected size of OUT transfers. No way to stop it without error.
When you design an original protocol carried over USB, you have to make "expected transfer size" always clear for the firmware. For transfers of fixed length, For transfers of variable length, Tsuneo [This message has been edited by Tsuneo (edited July 31, 2008).] IP: Logged |
|
aaa1982 Member |
I think it is a good document for the understanding of USB transfer. thanks Tsuneo IP: Logged |
All times are CT (US) | next newest topic | next oldest topic |
![]() |
|
Have you seen our MCU Knowledge Base?