[STM32GENERIC] SerialUSB Print(F( speed and availableForWrite()

Pito
Sun Jun 18, 2017 4:00 pm
While messing with the Zmodem example:
1. we miss the Serial.availableForWrite() method
2. when I look at the SerialUSB speed while printing out a bunch of strings (via Serial.print(F(..)) ) my impression is it runs like 9k6, I would guess it should be the fastest mode we’ve got.. Maybe I do something wrong?

Pito
Sun Jun 18, 2017 4:59 pm
This is a bench for the Serial.print(F()) via SerialUSB (168MHz F407ZET):
UPDATE: println(F( vs. println(
// Serial.print(F()) via SerialUSB benchmark
// Pito 6/2017
void setup() {
Serial.begin(115200);
delay(3000);

uint32_t elapsed = micros();
for (uint32_t i = 0; i < 20; i++) {
Serial.println(F("THIS IS A TEST THIS IS A TEST THIS IS A TEST THIS IS A TEST THIS IS A TEST"));
}
elapsed = micros() - elapsed;

Serial.print("Elapsed with (F(: ");
Serial.print(elapsed);
Serial.println(" usecs");
Serial.println(" ");

elapsed = micros();
for (uint32_t i = 0; i < 20; i++) {
Serial.println("THIS IS A TEST THIS IS A TEST THIS IS A TEST THIS IS A TEST THIS IS A TEST");
}
elapsed = micros() - elapsed;

Serial.print("Elapsed: ");
Serial.print(elapsed);
Serial.println(" usecs");
}

void loop() {
}


danieleff
Sun Jun 18, 2017 5:07 pm
F407VE

THIS IS A TEST THIS IS A TEST THIS IS A TEST THIS IS A TEST THIS IS A TEST
Elapsed: 198278 usecs

Pito
Sun Jun 18, 2017 5:09 pm
That is 8x faster.. :(
My clocks config:
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;

Pito
Sun Jun 18, 2017 5:42 pm
Can somebody try under Win7, plz?

stevestrong
Sun Jun 18, 2017 6:46 pm
not generic, but just as comparison to libmaple F407Vet6:
Elapsed: 484 usecs

Pito
Sun Jun 18, 2017 6:59 pm
That is 3100x faster that mine.. So it seems it is something wrong with my F407ZET’s SerialUSB then :D

Pito
Mon Jun 19, 2017 10:39 am
I’ve updated the benchmark above and:
1. with Serial.println(“THIS.. it takes 39971 usecs
2. with Serial.println(F(“THIS.. it takes 1496123 usecs
So it seems the “F” is the issue here.. (Black F407ZET)

Pito
Tue Jun 20, 2017 11:57 pm
@Daniel and Steve: I do not understand how you can get such speeds with printing with “F”.
When stepping with debugger through it, the “F” prints each char individually via USB (after each write(c) below I see a new char appears in the TeraTerm terminal)
size_t Print::print(const __FlashStringHelper *ifsh)
{
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
if (c == 0) break;
if (write(c)) n++;
else break;
}
return n;
}

danieleff
Wed Jun 21, 2017 4:31 am
Libmaple has optimizes version of it
size_t Print::print(const __FlashStringHelper *ifsh)
{
return print(reinterpret_cast<const char *>(ifsh));
}

stevestrong
Wed Jun 21, 2017 4:40 am
For libmaple this is the time for copying the strings to the Tx buffer.
Only at the 27th TEST… string gets the buffer full… :)

Pito
Wed Jun 21, 2017 6:26 am
[danieleff – Wed Jun 21, 2017 4:31 am] –
Libmaple has optimizes version of it
size_t Print::print(const __FlashStringHelper *ifsh)
{
return print(reinterpret_cast<const char *>(ifsh));
}

Leave a Reply

Your email address will not be published. Required fields are marked *