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?