[libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Cores are the underlying magic that make the Arduino API possible
Post Reply
victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

[libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Post by victor_pv » Sat Aug 12, 2017 2:41 am

While doing some speed tests on the USBSerial I have noticed the libmplae F4 core will drop bytes if the application is not reading them.
I understand the F1 doesn't drop bytes, is it desired to drop those bytes?

To test, just write a sketch that opens the serial port, reads a few bytes, and then loops not reading any more.
Then open a terminal in the computer and send whatever you want, and will be sent. The host will not stop sending as long as the sketch has not crashed.

User avatar
RogerClark
Posts: 6413
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Post by RogerClark » Sat Aug 12, 2017 3:18 am

From what I can remember, there have been some fixes applied to the usb serial on the F1, but AFIK none have been applied to the F4

I don't know if they share much common code and whether the F1 changes can simply be manually copied over, or whether the fixes would need to be ported to the F4

victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

Re: [libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Post by victor_pv » Sat Aug 12, 2017 4:56 am

RogerClark wrote:
Sat Aug 12, 2017 3:18 am
From what I can remember, there have been some fixes applied to the usb serial on the F1, but AFIK none have been applied to the F4

I don't know if they share much common code and whether the F1 changes can simply be manually copied over, or whether the fixes would need to be ported to the F4
They don't have much in common, the F1 is libmaple's own, while the F4 is from STM SPL. I have started working on changing that, so it stops sending ACKs when the buffer is full, but I was wondering if that was for some reason the desired behaviour.

User avatar
RogerClark
Posts: 6413
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Post by RogerClark » Sat Aug 12, 2017 6:39 am

I've not looked in that much detail.

I did notice however that on the F1 the code only puts bytes in the output buffer if DTR is set.
This causes problems for some terminals (and specifically some HAM radio software), because the terminal does not set DTR.

Apparently the Arduino Due etc, still put data into the output buffer even if the Host has not set DTR and can't receive the data.
But when I tried changing the F1 code I got some undesirable results, where I think it causes the main thread to hang once the buffer is full

Ideally on the F1 it should work the same as the Due etc, but I don't have time to investigate how to make the necessary changes, and its not effecting may people

victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

Re: [libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Post by victor_pv » Sat Aug 12, 2017 2:29 pm

RogerClark wrote:
Sat Aug 12, 2017 6:39 am
I've not looked in that much detail.

I did notice however that on the F1 the code only puts bytes in the output buffer if DTR is set.
This causes problems for some terminals (and specifically some HAM radio software), because the terminal does not set DTR.

Apparently the Arduino Due etc, still put data into the output buffer even if the Host has not set DTR and can't receive the data.
But when I tried changing the F1 code I got some undesirable results, where I think it causes the main thread to hang once the buffer is full

Ideally on the F1 it should work the same as the Due etc, but I don't have time to investigate how to make the necessary changes, and its not effecting may people
I remember that issue with the sketch handing (it felt like slowing down) if USB was disconnected and the sketch was sending.
If the host is disconnected, and the due keeps taking bytes for sent, they must be dumped somewhere. I'll try to have a look at what the due does if I can find that section of their core.
In the F4 I haven't tested about sending from MCU to host, only from host to MCU, so I can't say how that direction works, but will have a look.

User avatar
RogerClark
Posts: 6413
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple F4] Serial USB drops bytes if the sketch doesn't read fast enough

Post by RogerClark » Sat Aug 12, 2017 9:09 pm

I suspect the Due effective looses the older items in the TX buffer, where as, I think we loose the newest text, as I think our code stops putting it in the buffer, when the buffer is full

Ideally, we should discard the oldest text from the buffer, but fixing this is low on my To Do list, as no one has reported it as a problem
In fact, when the host connects , e.g. You open the terminal window in the IDE, you never seem to see the backlog of text that is in the buffer.
I will need to see if it's just the Arduino IDE terminal that does this, and also if it's just a Windows thing.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest