[STM32GENERIC/HAL] SerialUSB TX/RX speed problem

Discussions about the STM32generic core
Post Reply
User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

[STM32GENERIC/HAL] SerialUSB TX/RX speed problem

Post by Pito » Mon Jul 17, 2017 8:15 am

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..
Last edited by Pito on Mon Aug 14, 2017 5:43 am, edited 8 times in total.
Pukao Hats Cleaning Services Ltd.

stevestrong
Posts: 1735
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [STM32GENERIC] SerialUSB TX speed problem

Post by stevestrong » Mon Jul 17, 2017 8:31 am

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);

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by danieleff » Mon Jul 17, 2017 3:08 pm

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

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by Pito » Wed Jul 19, 2017 11:10 am

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..
Last edited by Pito on Wed Jul 19, 2017 5:14 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by Pito » Wed Jul 19, 2017 11:25 am

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
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by Pito » Fri Jul 21, 2017 7:47 am

@Daniel: what compiler version do you use? Even with your vanilla repo I cannot get more than 64kB..
Pukao Hats Cleaning Services Ltd.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by danieleff » Fri Jul 21, 2017 8:12 am

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.

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by Pito » Fri Jul 21, 2017 9:25 am

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
Last edited by Pito on Sun Jul 23, 2017 6:34 pm, edited 3 times in total.
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by Pito » Sun Jul 23, 2017 12:13 pm

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..
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC/HAL] SerialUSB TX speed problem

Post by Pito » Sun Jul 23, 2017 6:31 pm

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.
Pukao Hats Cleaning Services Ltd.

Post Reply