C++ test USB serial port rate

I want to test the STM32F429 and Linux USB serial port rate. I have talked about all kinds of software on the Internet. It seems that all kinds of software can't be used. Wireshark's USB cap doesn't work. Just write a program to test it!

 The method of testing the execution time of the program does not work when testing the serial port (clock, time, etc.), you need to use a thread to test:

#include "serialPort.hpp"
#include <pthread.h>
#include <iostream>
char buff[512];
long counter;
const char *dev  = "/dev/ttyS36";
void * time_task(void * arg) {
  while (true)
  { 
  cout<<"baud rate:"<<counter*8/1024.0<<"Kbps"<<endl;
  counter=0;
  sleep(1);
  }
   return 0;
}
int main()
{ 
   pthread_t threadId;
    pthread_create(&threadId, NULL, &time_task, NULL);
serialPort myserial;
int i,nread,nwrite;
  cout<<"serialPort Test"<<endl;
  myserial.OpenPort(dev);
  myserial.set_speed(115200);
  myserial.set_Parity(8,1,'N');
  counter=0;
  while (true)
  {
//	  nwrite = myserial.writeBuffer( buff, 8);
  nread = myserial.readBuffer( buff, 512);  
  counter=counter+nread;
 
  }
}

serialPort is a class written by myself, which was introduced in my previous blog post. If you need it, you can send a private message.

mbed program on stm32

/*
 * Copyright (c) 2006-2020 Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 */
#include "mbed.h"
#include "USBCDC.h"

USBCDC cdc;

int main(void)
{
        uint8_t buf[512];
        for (int i=0;i<512;i++)
          buf[i]=0x30;
          buf[510]=0x0d;
          buf[511]=0x0a;
    while (1) {
     
        cdc.send(buf, 512);
        ThisThread::sleep_for(1);
    }
}

The actual test result is

That's it, about 4Mbps. The block grows up a bit, and the rate is much higher.

      If you want to further increase the USB speed, you must select USB 2.0 HS mode. Need an external USB HS phy, such as USB3300, currently STM32F7x3 and STM32F730. Support the built-in USB HS phy. mbed OS does not currently support USB HS

Guess you like

Origin blog.csdn.net/yaojiawan/article/details/108790475