defragster
Senior Member+
As noted - the problem is on the 'Host' side with send rates it isn't capable of keeping up with. When the device properly constrains the rate of output - the host receives the USB certified data.
That shows 19 consecutive runs against TyCommander as SerMon - I ran again and did get TyComm buffer garbage once.
Then Ran HTerm with repeat every 0.6 secs ( nice feature ):
23 iterations against HTerm counts 31,260,335 bytes - total transfer time about 1.9 seconds
Code updated - see following post
Here is the gated sketch on T_4.1 that runs:
That BOLD while is essential to decent function - No count of the number of times it runs was made, but with that 'break' to allow buffer transfer the host was able to keep up and get valid data
Code:
in 83606 microseconds bytes printed 1358975
DONE with Serial.availableForWrite() 6144 bytes printed1359031
134528
94468
82122
80400
80917
81530
83485
91171
79962
80900
79729
80146
79757
80651
78930
79543
81370
85431
83606
That shows 19 consecutive runs against TyCommander as SerMon - I ran again and did get TyComm buffer garbage once.
Then Ran HTerm with repeat every 0.6 secs ( nice feature ):
Code:
in 78573 microseconds <9> bytes printed<9>1358975<\r>
DONE with Serial.availableForWrite() 6144<9> bytes printed1359031<\r>
<9>79931<\r>
<9>87684<\r>
<9>79127<\r>
<9>82425<\r>
<9>82524<\r>
<9>82398<\r>
<9>82751<\r>
<9>81820<\r>
<9>82652<\r>
<9>81065<\r>
<9>82197<\r>
<9>84160<\r>
<9>77892<\r>
<9>79228<\r>
<9>82198<\r>
<9>79504<\r>
<9>82649<\r>
<9>85746<\r>
<9>80033<\r>
<9>78824<\r>
<9>82272<\r>
<9>81643<\r>
<9>78573<\r>
23 iterations against HTerm counts 31,260,335 bytes - total transfer time about 1.9 seconds
Code updated - see following post
Here is the gated sketch on T_4.1 that runs:
Code:
// https://forum.pjrc.com/threads/67870-Test-of-Serial-Transfer-fails-for-large-transfers
static uint32_t cnt = 0;
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 8000 );
cnt += Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
cnt += Serial.println("Send USB data to get output ...");
}
char databuffer[4096];
#define NumRuns 30
uint32_t sTimes[NumRuns];
uint32_t iiT = 0;
void loop() {
uint32_t cntW = 0;
if ( Serial.available() ) {
while ( Serial.available() ) Serial.read();
char *pc = databuffer;
cnt += Serial.printf( "Starting with Serial.availableForWrite() %u\n", Serial.availableForWrite() );
int n;
for (n = 0; n < 130; n++ ) {
pc[n] = 'a' + n % 26;
}
pc[n++] = '\n';
pc[n++] = 0;
uint32_t prTime = micros();
for (n = 0; n < 10000; n++ ) {
cnt += Serial.print( n );
cnt += Serial.print( "\t" );
cnt += Serial.print( databuffer );
[B] while ( Serial.availableForWrite() < 132 ) { // T_3.2 and ??? has max 64B USB buffers so 132 will halt sketch here unless changed. Max Bytes printed early in setup().
Serial.flush();
//delayMicroseconds(25);
cntW++;
}[/B]
}
prTime = micros() - prTime;
cnt += Serial.printf( "\nin %lu microseconds \t bytes printed\t", prTime);
cnt += Serial.println(cnt);
cnt += Serial.print("Count While flush repeat : ");
cnt += Serial.println(cntW);
delay(4);
sTimes[iiT++] = prTime;
if ( iiT >= NumRuns ) iiT = 0;
uint32_t tSum=0;
uint32_t iiS=0;
for ( uint ii = 0; ii < NumRuns; ii++) {
if ( sTimes[ii] != 0 ) {
iiS++;
tSum+=sTimes[ii];
cnt += Serial.print("\t");
cnt += Serial.println(sTimes[ii]);
}
}
cnt += Serial.printf( "\tTx us sum=%lu Tx us Avg= %u\n ", tSum, tSum/iiS );
cnt += Serial.printf( "DONE with Serial.availableForWrite() %u\t bytes printed\t", Serial.availableForWrite() );
cnt += Serial.println(cnt);
}
}
That BOLD while is essential to decent function - No count of the number of times it runs was made, but with that 'break' to allow buffer transfer the host was able to keep up and get valid data
Last edited: