Hello,I am trying to use the Virtual Comm Port (VCP) capability in the STM32 USB Host Device Library V2.1.0 on a STM32F207. But I am relatively new to implementing a USB device and the STM32 USB libraries, so I would appreciate any comments on the following points:
I am building a device that is to log text based data then upload it to a purpose written application when plugged into a (Widows based) Host PC. As I see it, I want to implement this connection as a Virtual Comm Port over USB, for the following reasons:
- I can use ST’s Virtual Comm Port Driver at the PC end and not have to write any sort of USB driver code at the PC end - my purpose written PC application only needs to know how to operate a (virtual) serial port,
- I have significant experience at communicating with embedded microcontrollers across simple RS-232 serial interfaces, which I understand the VCP connection will emulate, so I expect to be able to use my established techniques,
- And of-course, RS-232 ports on PCs have become rare and USB is built into the STM32…
I assume my thinking is all reasonable so far, though if anyone thinks differently I would be interested to know your thinking on this.
In practice, I will need to send commands (tens of bytes) from the Host PC to the STM32 and receive kilobytes or megabytes of data back (in some sort of block protocol, perhaps 1Kbyte at a time). So, the first question is, what sort of transfer rate (STM32 to PC) can I realisticly expect ? I understand the serial port baud rate is meaningless on a USB VCP connection, but I believe there is a limit (on USB 2.0 and using the STM32’s OTG_FS port) of about 6Kbyte per second, due to bandwidth sharing on the USB connection. Is this correct ? If it is correct, am I likely to achieve this, or in practice are there other factors that are likely to limit the throughput further ? 6Kbyte per second is acceptable, though faster would be better - should I be considering a different USB based approach ?
Also, I have been experimenting with ST’s VCP driver, and I don’t quite seem to understand how to use the VCP_TxData function. I understand I use this method to copy the data I want to send to the Host PC into a ring buffer, and the VCP driver periodically transfers the data I have placed in this buffer up to the Host PC. But how do I know when I can add more data to the buffer – how do I know when the buffer is full, or empty ? How do I avoid overwriting data in the buffer that hasn’t been sent yet ? It seems to me (and some entries on this forum seem to confirm this) that it is simply assumed you wont generate outgoing data faster than the VCP driver can dispose of it, but in my case, that is not really correct. While I could simply make the ring buffer bigger, that’s not really the answer, is it ? Shouldn’t there be a way to test if the buffer is full or empty or how much space is currently available in it ? If this function has been provided, I seem to have missed it, so I would appreciate anybody explaining to me how this works. Or if this function hasn’t been provided, I would appreciate anybody explaining how they have dealt with this problem.
Thanking you for your assistance,