0

Please follow the steps outlined in this discussion if you would like to run the following sketch yourself as Serial.flush blocks forever without the correct patch. The current Arduino release implements these changes but we can't download the new version from Board Manager as of the time of writing this (11/12/2021)...

After getting Serial.flush working, I use the following sketch in an attempt to measure the data transfer rates of the Nano 33 BLE Sense and the Portenta H7's USB virtual serial ports which were 11199 bytes/s and 19620 bytes/s, respective:

const byte BYTE_TO_SEND = 170; //b'10101010'.
const unsigned long NUMERATOR = 1000000000;

void setup(){
  Serial.begin(115200); //Does nothing on the nano 33 ble sense.
  while (!Serial); //Wait for serial port to connect. Needed for native USB on nano 33 ble sense.
}
  
void loop(){
  unsigned long startClock = micros();
  for (int i = 1000; i > 0; i--) {
    //Serial.write(BYTE_TO_SEND); //11199 bytes/second on nano33blesense.
    Serial.write(BYTE_TO_SEND); //19435-19620 bytes/second on portenta h7.
    Serial.flush();
  }
  unsigned long endClock = micros();
  
  unsigned long bytesPerSecond = NUMERATOR / (endClock-startClock);
  Serial.println("");
  Serial.print(bytesPerSecond);
  Serial.println(" bytes/second");
  while(1);
}

I am disappointed with these results ): The guys from this older post on the Arduino Forum who did a similar speed test with the Arduino Leonardo measured 39258 bytes/s! Any ideas on how I can get as fast, or hopefully, faster rates?

Or perhaps the measurement strategy is faulty?

Landon
  • 528
  • 2
  • 4
  • 22
  • 1
    Your data rates are slower than the other *"guys"* probably because your code only sends one byte at a time (plus with a flush, aka drain delay, to make it even slower). Maximum throughput is achieved by minimizing system overhead, minimal number of syscalls, maximizing buffers, and using largest packet size possible. Instead on just one byte, try different sizes up to 4KB. – sawdust Nov 12 '21 at 22:04
  • For maximum throughput info on USB CDC ACM, see https://stackoverflow.com/questions/44275560/what-is-the-maximum-speed-of-the-stm32-usb-cdc – sawdust Nov 13 '21 at 00:15
  • @sawdust, my code is almost identical to that which they used. I thought maybe they got a better speed because they used a faster USB connector like the USB 3.1 vs my USB 3.0 but that can't be the case as USB 3.1 released in 2013 and the post is from 2012. – Landon Nov 13 '21 at 02:30
  • @sawdust Also I have trouble understanding how to increase my speed based on the advice given in the provided link. Would you be willing to illustrate your point in the form of an answer with a sketch idea I could run myself? – Landon Nov 13 '21 at 02:32

0 Answers0