11 years, 4 months ago.

Performance issues with USBHostSerial, RTOS? Help needed!

Hi,

I need some help with the new USBHostSerial library.

I am connecting an USB sensor via the newly released USBHostSerial library to an mbed. The device is detected, I can sen commands and receive correct replys from the device! That's great.

However, I am worrying about speed. I measured time needed to perform the request, and depending on the command, it takes up to 13 milli seconds to transmit the data. I connected the same sensor via SPI (it provides multiple interfaces), here the same command and the reply from the device takes approx. 300 usec!

So my question is: What is eating up the performance, USBHostSerial or RTOS? The mbed I use for this project runs at 96 Mhz, so basically this should be sufficient...

Here is my code, based on your example. I moved the former separate USB thread into the main routine, didn't change anything..

int main() {
    USBHostSerial serial;
    //serial.baud(9600);
    t.reset();
    t.start();
    pc.baud(460800);
    wait(2);
    pc.printf("Hello, program starts\r\n");
    
    while(1) {
    
        // try to connect a serial device
        while(!serial.connect()) wait(0.5);
     //       Thread::wait(500);
        
        // in a loop, print all characters received
        // if the device is disconnected, we try to connect it again
        while (1) {
           pc.printf("Try connect\r\n");
        
            // if device disconnected, try to connect it again
            if (!serial.connected())
            {  
                //Not connected
                pc.printf("NC\r\n");
                break;
                }
                else
                {
                pc.printf("# %d :",t.read_us());
                t.reset();
                
                //This sends the command to the sensor: Request hardware version (returns 32 byte string)
                serial.printf(":230\n");
                }
            char cx;
            
            pc.printf("#2 %d :",t.read_us());
            
            // print characters received
            while (serial.available()) {
                cx = serial.getc();
                printf("%c", cx);
            }            
            
            i
            pc.printf("#3 %d :",t.read_us());
            
            pc.printf("\r\n");
            
        }
    }

My terminal output looks like this:

<<code>> Try connect

  1. 12805 :#2 9628 :TSS-EM v1.0.0 <</code>>

1 Answer

11 years, 4 months ago.

The USB protocol has relatively high latencies and 13 ms does not sound unusual to me. Putting serial protocol on top of it does not improve things either.

If you want speed, I2C or SPI is usually a much better choice.

http://www.datatranslation.com/phpkb/question.php?ID=627

Hi,

thank you for your reply. I looked at the site you've linked, that was pretty informative. I did not not know that 1 ms was the minimum. However, this information mostly relates to Windows systems. I planned to use a microcontroller in order to avoid all the interference from such a complex system and instead apply a microcontroller which directly accesses the USB device. It seems as if I need to think about SPI again. I am just worried about this option, since the cable length would roughly be ~ 25 cm and externalized and it would need to be flexible... I thought USB would fit better..

posted by Tobias Piroth 20 Mar 2013

For longer lines RS485 is a good choice if it supports that, however at 25cm I wouldn't worry too much about it, that is fairly short.

posted by Erik - 20 Mar 2013