Description
Description
- Type: Enhancement
- Related PR: Deprecate Stream and Serial #5655
- Related: this comment by @kjbracey-arm
- Priority: Major | Minor
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:
- while maintaining line buffering when using
Serial
- when using
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:
char const SerialStreamPath[] = "/serial";
char const *SerialStreamName = &(SerialStreamPath[1]);
Serial s(P0_0 , P0_1 , SerialStreamName, SERIAL_BAUD_RATE);
int main()
{
// https://os.mbed.com/users/simon/code/stdout/docs/tip/main_8cpp_source.html
freopen(SerialStreamPath, "w", stdout);
//...
}
But that's suboptimal, because it makes stdout
fully buffered instead of line buffered. (Maybe I could make it line buffered again by calling setvbuf()
, but then I'd be wasting whatever buffer was already set aside for stdout
.)
AFAICT, we can't do that on a UARTSerial
object, though, since it doesn't have a ctor with the name
parameter.
(I first asked part of this question here.)
Suggested enhancement
Allow user to redirect stdin
, stdout
, and/or stderr
- individually or together - to an arbitrary UART port - probably when using an object of any class that inherits from SerialBase
. 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 to SerialBase
, or some other way. In any case, please give examples in the official docs.