-
Notifications
You must be signed in to change notification settings - Fork 3k
allow redirecting stdio to arbitrary UART #6019
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
Comments
Unless I'm missing something, what you're asking for is one of the 4 things provided by #5571, and the most-discussed:
You just implement
The existing The pattern above better reflects the reality of "opened on construction" for those device-like objects and allows linker exclusion if the "give me the filehandle" function is never called.
As such, there is no existing class you can use to neatly override non-buffered with Mind you, rather than using the fully-generic "override to an arbitrary device" mechanism, it would possibly be easier for the simplest serial case to just add two more JSON option for
The newest 2 options - baud and buffered are JSON; the original pin options are fixed by the target. If the application could just override Looking at the example linked - https://os.mbed.com/users/simon/code/stdout/docs/tip/main_8cpp_source.html - that pattern wouldn't quite mesh with #5571. There's no Still, it's potentially inefficient, because you're still including all the code and initialisation of the original |
There's a lot of things going on over at #5571. Yes, my request here does appear to be covered by that. Thanks for pointing it out.
How will a user maintain line buffering on a redirected stdio with this method? (BTW, typo in your first code block -
As you suggest, it may be best to maintain existing functionality, even if that's not going to be the recommended way to do it (for good reason).
Are you talking about making both of these methods work, or just one? If both, fine by me. If just one, I'd be concerned if you choose [2], since IME using JSON files can limit |
The FileHandle's However, newlib-nano fails to call Method [1] is definitely staying, I'm just saying we could extend the existing JSON for the built-in serial too. On the other hand I am wanting to avoid a pattern where every single potential device and its parameters (serial, SWO, Segger RTT) ends up in mbed_retarget.cpp. Another possibility is something like a JSON option Not familiar with that particular export behaviour - raise it as an issue? |
I see that
|
Description
Enhancement
Reason to enhance or problem with existing solution
AFAIK, there is no way for a user to redirect
stdin
/stdout
/stderr
to an arbitrary UART object:Serial
UARTSerial
(IDK the situation with other
*Serial
classes.)The only way I know how to do it now for a
Serial
object is like this:But that's suboptimal, because it makes
stdout
fully buffered instead of line buffered. (Maybe I could make it line buffered again by callingsetvbuf()
, but then I'd be wasting whatever buffer was already set aside forstdout
.)AFAICT, we can't do that on a
UARTSerial
object, though, since it doesn't have a ctor with thename
parameter.(I first asked part of this question here.)
Suggested enhancement
Allow user to redirect
stdin
,stdout
, and/orstderr
- individually or together - to an arbitrary UART port - probably when using an object of any class that inherits fromSerialBase
. Maintain line buffering by default if the new source/destination is a UART.I don't have a strong opinion yet on what the interface should be. e.g. If you do the
freopen()
POSIX way, or if you add say "retarget" functions toSerialBase
, or some other way. In any case, please give examples in the official docs.The text was updated successfully, but these errors were encountered: