G80 / USB CDC Client problems?

Hi, I’m using a G80 dev board with the pre-release SDK.

We are finding when we send data over a USB CDC Client connection to the host, extra data is being padded.

For example, if we call cdc.Stream.Write (buffer, 0, 1024), we get 1027 bytes on the host side. The padded bytes are always the same: 0x00, 0x09, 0x01

Known issue with the GHI CDC class? We also tried writing a CDC client using the Microsoft.SPOT.Hardware.Usb constructs, and this symptom is not present.

@ dguit - according to the CDC documentation: https://www.ghielectronics.com/docs/20/usb-client#106

[quote]Note: CDC drivers usually handle one transaction in every frame. The max EP size on USB is 64 bytes and there 1000 frames per second on full-speed USB. This means that the maximum transfer rate for CDC drivers is 64KB/sec.

Could this be the issue?

@ Mike - That’s an interesting point to raise, also. We are finding that this is NOT how the GHI CDC client actually works.

The statement about 64KB/sec max transfer rate suggests a theoretical and guaranteed maximum transfer rate for interrupt endpoint-driven USB devices, at full speed, using the 64 byte max EP size, and 1ms polling interval.

We initially created a custom HID class device using two interrupt endpoints, and found exactly that - 64KB/sec transfer speed.

However, the GHI CDC client creates bulk endpoints for data transfer, not interrupt endpoints. Our understanding is it can use whatever bandwidth is available on the USB to transfer data, and as such, we’re seeing about 808KB/sec.

@ dguit -

For padding data issue, it relates to multiple of 64. We will fix in next release.
Workaround here is, don’t send any size if it is multiple of 64. If you have 1024 then send 1023 and then 1. It should work fine.

const int BLOCK_SIZE = 63;
        void WriteMultiple64(byte[] data)
            int block = data.Length / BLOCK_SIZE;
            int remain = data.Length % BLOCK_SIZE;

            int offset = 0;
            while (block > 0)
                cdc.Stream.Write(data, offset, BLOCK_SIZE);
                offset += BLOCK_SIZE;
            if (remain > 0)
                cdc.Stream.Write(data, offset, remain);
                offset += remain;

@ Dat - Fantastic, thank you very much, Dat.