cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID or CDC

hilwan
Associate II
Posted on March 12, 2014 at 11:01

Hi, 

I have implemented the CDC(VCP) class on my F3 discovery and it work very well. Now, i want to send a integer data each 25µs. So i have to set up my rate speed of my board to 1600Kbps.

On the PC side, the speed rate of my serial port is limited to 115Kbps.

Is there any way to get the PC and the board working at the same speed 1600Kbps?

Actually,i implemented HID class, my device is detected as HID device but i haven't tested the communication yet. I saw that the maximum speed is 64Kbytes/s. So, this solution can't resolve my problem.

Do you have any idea how can i achieve this stuff ?

I really need to use USB to communicate with my Board.

Thanks in advance for any help,

Best regards 

15 REPLIES 15
chen
Associate II
Posted on March 12, 2014 at 15:09

Hi

''On the PC side, the speed rate of my serial port is limited to 115Kbps.''

Strictly speaking, this is a emulation of Serial over USB. Due to this fact, the speed (bits per second) is actually (almost) irrelevant.

On the PC the actual limit is 1)how fast the VCP driver empties the USB buffer 2)how the PC terminal application deals with the speed of the data stream.

On the STM32, I still have not figured out what causes/triggers data to be sent/received in the USB OTG driver (on my todo list - just too much other high priority stuff) . This will govern the maximum data rate on the STM32.

hilwan
Associate II
Posted on March 12, 2014 at 16:03

Thank you sung.chen_chung for your reply.

I'm not familiar with kind of peripheral, i tried just to adapt the example given by ST to fit my application.

I'm sorry, i don't understand your 1) and 2) explications. What should i modify to increase the speed both in STM32 side or PC side.

One thing, i developed an .Net graphical interface to send and receive my data sent by F3 Disco. In this interface, the baud rate can be changed but i noticed that doesn't increase the speed in the PC side. Because i have a lost data sent by my device.

chen
Associate II
Posted on March 12, 2014 at 16:36

Hi

''What should i modify to increase the speed both in STM32 side or PC side.''

''One thing, i developed an .Net graphical interface to send and receive my data sent by F3 Disco. In this interface, the baud rate can be changed but i noticed that doesn't increase the speed in the PC side. Because i have a lost data sent by my device.''

On the PC side - the baud rate does not play must of a part in Virtual Com Port (or at least I do not think it does).

The VCP driver deals with getting the data from USB. Unless you re-write your own VCP driver - there is nothing you can do to increase the transfer speed at this layer. You are limited to how often the driver decides to send/receive data.

You said you developed your own application. This needs to receive the data as fast as possible from the 'serial port' (remember it is virtual) !

On the STM32. Are you using the STM USB Full Speed library or the STM USB OTG library?

In both cases, I do not know what actually causes the data to be sent, something in the driver and in the peripheral hardware.

How often and the size of data will determine your data rate.

You can call the driver code to 'send to host' as often as you like but there is something in the driver that actually triggers a send over PHY at regular intervals. I have not figured this out yet (for OTG driver)

Sorry - I do not know how to increase the data rate on STM32 (yet)

hilwan
Associate II
Posted on March 12, 2014 at 17:09

I'm working on the F3 discovery and i'm using ''STM USB Full Speed library''

I use the 'ST VCP driver' and i'm using the ''bulk mode'' to receive and send data .

In the usb_prop.c, there is a structure that supposed to define the baud rate :

LINE_CODING linecoding =

  {

    115200, /* baud rate*

    0x00,   /* stop bits-1*/

    0x00,   /* parity - none*/

    0x08    /* no. of bits 8*/

  };

I modified this to get the baud rate i want but no success

chen
Associate II
Posted on March 12, 2014 at 17:21

Hi

You are not understanding the definition of 'virtual'.

The baud rate on a real RS232 Comm port relates to the number of bits per second.

When you look at the RS232 on an oscilloscope - you can actually measure the pulses and they will correspond to the baud rate that is set.

On a Virtual Com port over USB - the baud rate is just these to help simulate a RS232 port. The baud rate is not actually of any use.

In theory, you can set the baud rate to 110 and still send at any rate you like!

(It is up to the program at either end to cope with what ever the data rate actually is!)

What limits the data rate is

1) how often host and target service the USB

2) how much data is in the USB packets

3) USB protocol version - FullSpeed = USB2 ( '' rate of 480 Mbit/s (effective throughput up to 35 MB/s or 280 Mbit/s )'' - from wikipedia)

The only useful idea is to target 2)

Pack more data into each USB packet.

You can call the 'USB send to host' as often as you like.

The driver will handle sending the data at regular intervals.

zzdz2
Associate II
Posted on March 12, 2014 at 17:59

You can look at EP1_IN_Callback (IN endpoint sends data from device to host) and Handle_USBAsynchXfer functions (it looks like one of those should be responsible).

The sequence to send data would be something like this:

  UserToPMABufferCopy -> copy data to PMA buffer

  SetEPTxCount(ENDP1, USB_Tx_length); -> set length

  SetEPTxValid(ENDP1);  -> say to usb that the data is ready to send

dthedens23
Associate II
Posted on March 14, 2014 at 21:18

3) USB protocol version - FullSpeed = USB2 ( '' rate of 480 Mbit/s (effective throughput up to 35 MB/s or 280 Mbit/s )'' - from wikipedia)

No,

Full speed is 64 bytes max per packet  12Mbs

High speed it 512 max (except isoc) bytes per packet 480Mbs

you want to go faster, use a part with a High Speed USB Phy.
zzdz2
Associate II
Posted on March 15, 2014 at 09:13

Full speed is 64 bytes max per packet  12Mbs

Good point

High speed it 512 max (except isoc) bytes per packet 480Mbs

you want to go faster, use a part with a High Speed USB Phy.

Full-speed allows 19 bulk packets of 64 bytes per frame.

It's 1216 kB/sec, I don't think we need more here.

stm322399
Senior
Posted on March 15, 2014 at 17:59

You correctly calculated the maximum theoretical bandwidth.

But to achieve that comfortable figure, you need extra conditions to be met:

* on the slave side, you need to feed 64B buffers every 52µs. It's generally easy as you have a dedicated SRAM, you can keep filled.

* on the host side, the driver must supply reception buffers at the same rate. Very often, USB host IP requires to prepare a linked list of buffers before the start of the frame.

In other words, the driver on PC can really make the difference. Example, linux generic serial driver only allocates 2 buffers (see read_urbs in serial.h), whereas cdc-acm driver allocates 16 buffers (see cdc-acm.h). Try to guess which driver will give you the best data rate ?

A couple of month ago, I found in the wild a comparison table of USB serial data rate comparing Win*, OsX and Linux on host side, and arduinos/mapple/other embedded boards on slave side. Ask google if you're curious