Page 1 of 8

[STM32GENERIC/HAL] SerialUSB TX/RX speed problem

Posted: Mon Jul 17, 2017 8:15 am
by Pito
This is a short sketch to demonstrate the problem, fixed by steve's patch in libmaple:

Code: Select all

// USBSERIAL TX PROBLEM DEMONSTRATION
// Pito 7/2017

#include "Arduino.h"

void setup() {
  Serial.begin(115200);
  delay(3000);
}

#define TXCHARS 1000000

void loop() {
  uint32_t i;
  uint8_t x = 85;
  uint32_t elapsed = micros();

  for (i = 0; i < TXCHARS; i++) {
    Serial.write(x);
  }

  elapsed = micros() - elapsed;
  Serial.println("***");
  Serial.print("USB TX speed = ");
  Serial.print((1000.0 * TXCHARS) / elapsed, 2);
  Serial.println(" KBytes/sec");
  delay(1000);
}
With F103ZE @72MHz:
Current STM32Generic:

Code: Select all

***
USB TX speed = 1.00 KBytes/sec
Fixed libmaple by Steve:

Code: Select all

***
USB TX speed = 213.34 KBytes/sec
It seems the current version sends 1byte per USB packet (1ms packet period).
The previous libmaple gave the same number.

As Victor has demonstrated the F103 can receive 300-500kB/sec the question is whether the TX speed cannot
be even higher than 213kB/sec..

Re: [STM32GENERIC] SerialUSB TX speed problem

Posted: Mon Jul 17, 2017 8:31 am
by stevestrong
Pito wrote:
Mon Jul 17, 2017 8:15 am
Fixed libmaple:

Code: Select all

***
USB TX speed = 213.34 KBytes/sec
... the question is whether the TX speed cannot be even higher than 213kB/sec..
Of course it can, but for that you should use:

Code: Select all

Serial.write(buf,nr_bytes);

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Mon Jul 17, 2017 3:08 pm
by danieleff
A few weeks back I also added buffered USB TX, https://github.com/danieleff/STM32GENER ... 8154715833, https://github.com/danieleff/STM32GENER ... b86394c84e

Your code gives me:
USB TX speed = 308.41 KBytes/sec

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Wed Jul 19, 2017 11:10 am
by Pito
Great! I will try, I updated my local on 24.6. so maybe I miss your patch..

BTW, I've compiled the test for Black F407 @168MHz under my old libmaple (patched manually with steve's patch) and I get 1013-1064kB/sec..

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Wed Jul 19, 2017 11:25 am
by Pito
I've replaced the cores and the system with your latest and I get (Black F407ZE @168MHz)

Code: Select all

***
USB TX speed = 64.87 KBytes/sec
Blue F013ZE @72MHz

Code: Select all

***
USB TX speed = 64.45 KBytes/sec
Update: with newest libmaple from RG repo, F103ZE @72MHz

Code: Select all

***
USB TX speed = 224.12 KBytes/sec
Update1: with newest libmaple from RG repo, F407 @168MHz

Code: Select all

***
USB TX speed = 208.22 KBytes/sec

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Fri Jul 21, 2017 7:47 am
by Pito
@Daniel: what compiler version do you use? Even with your vanilla repo I cannot get more than 64kB..

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Fri Jul 21, 2017 8:12 am
by danieleff
I think it is 6-2017-q1-update from https://developer.arm.com/open-source/g ... /downloads, newest is 6-2017-q2-update

Also CDC_SERIAL_BUFFER_SIZE is still 128 in STM32/cores/arduino/usb/cdc/usbd_cdc_if.h , upping that might help.

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Fri Jul 21, 2017 9:25 am
by Pito
Ok, with CDC_SERIAL_BUFFER_SIZE 512 I get now with F407
DELETED
The standard compiler.

With CDC_SERIAL_BUFFER_SIZE 2048 I get with F407 730-994KB/sec.
DELETED

Update: with maybe more realistic scenario - with 1mil chars sent to TeraTerm terminal (Win7)

Code: Select all

#define TXCHARS 1000000
I get with F407ZE @168MHz
DELETED

And for F103ZE @72MHz
DELETED

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Sun Jul 23, 2017 12:13 pm
by Pito
The bigger buffers are fast, but TX looses the data :(

While running the Tek demo against TeraTerm Tek emulator
http://www.stm32duino.com/viewtopic.php ... =20#p31835

the buffer sizes larger than 256 bytes show corruptions in the picture..

The libmaple usb works, not sure on the buffer size there.
It could be the TeraTerm is causing that as well..

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Posted: Sun Jul 23, 2017 6:31 pm
by Pito
It seems my above results (the tables with speeds) were wrong.. :evil:
The Teraterm does not receive all 1mil chars with larger cdc buffer, but a fraction of it.
The larger the buffer in CDC the smaller amount of data I get.
Therefore the total time for TX was smaller and the TX speed was higher.

I've checked that by logging the incoming bytes into a file.
I get 1mil chars received ONLY with CDC_SERIAL_BUFFER_SIZE=128 (that is TX speed = 64kB/sec).

I've deleted the tables.

PS: with libmaple latest and its stock cdc settings I get 1mil chars with TX speed 120-170kB/sec.