-
Notifications
You must be signed in to change notification settings - Fork 3k
Deprecate Stream and Serial #5655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Serial is replaced by UARTSerial - this provides the necessary buffers to use serial reliably for input from non-interrupt contexts, and avoid excess spinning waiting for TX buffer space. (Historically, anyone using Serial but needing input has done so by bypassing its stdio-based calls, and instead making calls to the underlying SerialBase from interrupt, as the stdio input calls do not work reliably from threads due to lack of buffering, and can't be used from interrupts. This reliance on the underlying implementation means it wasn't possible to add buffering in a backwards-compatible fashion, hence the distinct UARTSerial). Because it no longer uses Stream, use of UARTSerial no longer necessarily forces pulling in the C library stdio system. Stream is replaced by drivers implementing FileHandle directly, and applications using fdopen(FileHandle *) to get a FILE * to use full C/C++ stream features. This avoids being locked into an odd design pattern whereby the class works at 2 layers: * Application - uses Stream-based driver * Stream - uses <stdio.h> FILE * * C library - Implements FILE *, uses FileHandle * Stream - implements FileHandle, uses virtual _getc/_putc * Derived-from-Stream (eg Serial) - implements _getc/_putc Stream's implementation of FileHandle on a simple blocking _getc/_putc cannot be usefully extended to the fuller FileHandle API required for real-life use like PPP or ATCmdParser. The revised setup now looks like: * Application - uses FILE * * C library - Implements FILE *, uses FileHandle * Driver - Implements FileHandle What we lose is the syntactical sugar that allowed you to do Serial serial(RX, TX, 115200); serial.printf("Hello"); Instead, you now must do UARTSerial serial(RX, TX, 115200); FILE *out = fdopen(&serial, "w"); fprintf(out, "Hello");
Attempt to complete tidy-up of the serial classes, by deprecating the classes that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On hold pending further investigation
I referenced this PR in issue #6019, but the pingback didn't show here (for whatever reason), so I'm leaving this comment. |
#5571 has been merged into Mbed OS 5.8.0 RC1. If the plan is still to deprecate these, I think it would be nice if you can get it in to Mbed OS 5.8.0, to help users discover that they should use |
Still subject to discussions - the fact so many people are using Latest thoughts were
(Although another discussion was suggesting a "Serial"->"UART" conversion generally including the HAL, so it might be Won't be happening for 5.8, and still not on the roadmap for 5.9 - only a very small proportion of developers seem to notice the |
Deprecation may be appropriate in a situation when there is a new and improved version, even when the original isn't bad. Right? Maybe deprecation isn't the right thing to do now. If not, hopefully you have a plan to determine if/when it will be... OTOH, why do both
Good point here. Related: #6295.
I can't recall performance issues with it, either. My issue was wanting proper stdio redirection without changing the buffering. I'm happy to say that seems to be working fine now with |
Original description on this PR goes through some of it - main blocker is that anyone who's managed to do reliable input on And the Therefore, we made the buffered serial a complete new implementation. The proposed future symmetry backfilling is to also make Serial's Basically anyone currently using Original commit adding |
@kjbracey-arm @ARMmbed/mbed-os-maintainers Is there any value in keeping this open considering the conversation has become stale? |
Am I interpreting the following correctly? In the following cases, deprecating
...fine - a helpful prompt to switch.
...OK? Can they just drop
...fine.
...I guess this is the tough one. Could there be a recommended migration plan here?
|
@cmonr Had some discussions with @sg- and other folks - we're going to do something - but I think we can park this PR for now. @bmcdonnell-ionx - re the fiddly case.
Depends what they're doing. Maybe the straight buffering of A new issue has recently come to my attention - serial interrupt handlers (and hence We need to address that in 2 ways:
|
Oh, and my point was that if we do do unidirectional open primarily for the sleep issue, then conceivably you could legally do |
Quick update on two of the things-to-do mentioned above, that have been done:
|
Serial
is replaced byUARTSerial
- this provides the necessary buffersto use serial reliably for input from non-interrupt contexts, and avoid
excess spinning waiting for TX buffer space.
(Historically, anyone using
Serial
but needing input has done so bybypassing its stdio-based calls, and instead making calls
to the underlying
SerialBase
from interrupt, as the stdio input callsdo not work reliably from threads due to lack of buffering, and can't
be used from interrupts. This reliance on the underlying implementation
means it wasn't possible to add buffering in a backwards-compatible
fashion, hence the distinct
UARTSerial
).Because it no longer uses
Stream
, use ofUARTSerial
no longernecessarily forces pulling in the C library stdio system.
Stream
is replaced by drivers implementingFileHandle
directly, andapplications using
fdopen(FileHandle *)
to get aFILE *
to use fullC/C++ stream features. This avoids being locked into an odd design
pattern whereby the class works at 2 layers:
FILE
FILE
, usesFileHandle
FileHandle
, uses virtual_getc/_putc
_getc/_putc
Stream's implementation of FileHandle on a simple blocking _getc/_putc
cannot be usefully extended to the fuller FileHandle API required for
real-life use like PPP or
ATCmdParser
.The revised setup now looks like:
FILE
FILE
, usesFileHandle
FileHandle
What we lose is the syntactical sugar that allowed you to do
Instead, you now must do