How to achieve maximum USB transfer speed on STM32 F1xx?

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome.
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm
Location: Novosibirsk, Russia

How to achieve maximum USB transfer speed on STM32 F1xx?

Postby kab » Wed Sep 19, 2012 5:40 pm

hi!

I would like to ask - what transfer speed expected in USB CDC driver for F103 device?
I've read, that for F4 it's around 1.1 mb/s.

I wrote simple python script:

Code: Select all

import serial
import time

ser = serial.Serial('COM53', baudrate=2000000, timeout=1)

ser.write('write\r')

cnt=0
cnt_max = 1024*1024*10

t1 = time.time()

while True:
   data = ser.read(4096)
   if not data or len(data)==0:
      break

   cnt = cnt + len(data)

   if cnt>cnt_max:
      break

print 'Readed', cnt_max, 'bytes in ', time.time() - t1, 'sec'

and run it together with USB CDC F1xx example.

and got around 180 kb/s.

this is maximum or i doing something wrong?

User avatar
Giovanni
Site Admin
Posts: 12168
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 567 times
Been thanked: 487 times
Contact:

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby Giovanni » Wed Sep 19, 2012 5:45 pm

If you use the Serial_USB driver then the performance is influenced by the queues size, you may try to increase those, of course the code must be able to generate data fast enough, also, throughput through queues is lower than writing large linear buffers, you may consider using linear buffers and do not go through Serial_USB.

The driver itself does not support yet double buffering, that could increase performance but I have not any proof of that yet.

Giovanni

kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm
Location: Novosibirsk, Russia

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby kab » Wed Sep 19, 2012 5:50 pm

Can you please point me to example - how to send big linear buffer?
Most fastest way?

User avatar
Giovanni
Site Admin
Posts: 12168
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 567 times
Been thanked: 487 times
Contact:

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby Giovanni » Wed Sep 19, 2012 5:59 pm

usbPrepareTransmit()
usbStartTransmitI()

Then a callback will tell you it is over and you can send more data.

Giovanni

kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm
Location: Novosibirsk, Russia

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby kab » Wed Sep 19, 2012 6:03 pm

sorry for dummy questions: and from PC side - this will be some other USB device? not serial port?

User avatar
Giovanni
Site Admin
Posts: 12168
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 567 times
Been thanked: 487 times
Contact:

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby Giovanni » Wed Sep 19, 2012 6:50 pm

It can be a serial port, that only depends on the descriptor strings.

Giovanni

kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm
Location: Novosibirsk, Russia

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby kab » Wed Sep 19, 2012 8:15 pm

Thanks for help!
I'm trying to understand structure of usb handling in chibiOs, but still miss. In CDC example, we already set callback to sduDataTransmitted/sduDataReceived (which defined in serial_usb.c). I can override this functions? Should i keep their functionality and just add own code (to notify that transmission is over and i can start again).

May be, if it's not hard for you, you can point me an example(s) or part of code how to do that without breaking usb_serial functionality?

My task is: by command from serial port send a lot of data (ADC samples) as fast as possible.

User avatar
Giovanni
Site Admin
Posts: 12168
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 567 times
Been thanked: 487 times
Contact:

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby Giovanni » Wed Sep 19, 2012 8:22 pm

You can remove serial_usb entirely, just keep the function that decodes the CDC-specific messages (sduRequestsHook()) then you can do the I/O on the data endpoints directly using the USB functions I posted previously.

I don't have an example right now, sorry.

Giovanni

kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm
Location: Novosibirsk, Russia

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby kab » Thu Sep 20, 2012 9:16 pm

Bad: I try and fail to use direct usbPrepare/usbTransmit (i commented out sduDataTransmitted in ep1config, write own handler and in cycle prepare and send new data, when got message, that transmission is over). Got just mess and did not get any data back.

Good: When i increase usb serial buffer size to 1024 bytes - i immediately got 400 kb/s transfer rate.

I google a bit and found on ST forum that this is almost limit without double buffering (http://tinyurl.com/bvflxwn):
It's around 400 - 500 Kbytes/sec. For STM32F103, enabling double buffer on the bulk endpoint, the speed will go twice.


However, when google a bit more i find other similar task solutions (like http://tomeko.net/miniscope_v2c/stm32scope_20120607.7z ) - where data transferred without double buffering at maximum (or near to maximum) speed (1 mb/s). Solution is simple - start transferring at SOF callback and at each ep1 callback (tranfer is over?) continue to send data. However, on link above guy did not just read VCPort, he use libusb to direct access to bulk data stream.

Question - does anyone able to reach such speeds (~1 mb/s) on STM Fxx device (on FS USB) with chibiOs?

kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm
Location: Novosibirsk, Russia

Re: How to achieve maximum USB transfer speed on STM32 F1xx?

Postby kab » Fri Sep 21, 2012 8:16 pm

JFYI, same test on STM32 F4 Discovery gives around 820 kb/s (via casual serial port), but for F4 fifo is enabled...


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 1 guest