-
Notifications
You must be signed in to change notification settings - Fork 3k
Serial design draft #11634
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
Serial design draft #11634
Conversation
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.
LGTM. I will give others a chance to review before approving.
@evedon, thank you for your changes. |
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.
Great work, looks like we can remove a lot of complexity and maybe even save some memory. Could you guys make sure the debug output can still be redirected to https://github.com/ARMmbed/mbed-os/blob/master/drivers/SerialWireOutput.h with this new architecture.
@evedon Are we missing a way to completely take out the re-targeting code if we do not need it? |
Silly question - what's the simplest way to view this as a whole with diagrams? |
|
||
 | ||
|
||
The POSIX layer and the static array of `FileHandle*` allocated by the retarget code for file handling consume a lot of memory. A constrained target that only uses a console does not need file handling and should be able to turn this functionality off. |
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.
Also the virtual-ness of the FileHandle means ROM.
1. Redefine the low-level library functions. A detailed description can be found [here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0475m/chr1358938931411.html) | ||
1. Redefine the system I/O functions. | ||
|
||
A minimal console only needs to write a single character at a time. So redefining the default fputc() to directly write to the serial port if the output stream is stdout and bypassing the system I/O functions should achieve higher memory savings. If we take this approach, we will have to rework some error handlers that rely on the POSIX form of `write(STDOUT_FILENO, buf, len)` to do emergency printing. |
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.
That method is also toolchain dependent - I don't know if we've established how easy it is with the other 2.
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.
Indeed the first approach looks more complex. We should only pursue if it brings more memory saving. We'll decide during implementation.
Oh, completely remove it? Interesting. I would hope that if you never actually call any stdio functions, nothing would get pulled in anyway. I believe stdin/stdout are initialised on first use, not actually pre-main. Maybe need to turn off the "flush on exit" option or something? But I can see some value in an option to make all definitions of the POSIX calls are minimal do-nothing stubs, even if there are lingering app calls. |
This looks good, happy with almost all of it, main concern is about the value of |
@kjbracey-arm |
All points addressed and |
Latest comments addressed in last commit. All commits squashed. |
Couple more thoughts on default changes - I'm advocating for
I'm rather indifferent on the baud rate, but I know some others are keenly in favour. (It's possible that lack of buffering and hence unreliable input may have been part of the reason for running slow originally.) But I'm continually annoyed by how much pointless |
This design focuses on serial classes and I am reluctant to increase the scope by including configurations changes. Having said that, I agree that if we advocate in the documentation for BufferedSerial to be the default serial choice the we should make For the other configuration changes, I am in favour of them but it is not part of this design. I created a JIRA ticket https://jira.arm.com/browse/IOTCORE-1423. We will try to address the ticket in this planning increment if there is time. |
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.
LGTM
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.
Looks good couple of nitpicks and questions about size impact.
|
||
### Scenario 1 `Printing to stdout` | ||
|
||
There is no change in the current APi in regard to printing to stdout. Applications should call `printf` directly as shown below. The console baud rate can be configured via `platform.stdio-baud-rate` in `mbed_app.json`. |
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.
I don't really like the should
, I would say can
and also add a small disclaimer, something like (it can negatively impact the image size)
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.
Negatively impact compared to what? I believe this section started as a comparator to Serial::printf
, and I think that's its focus. The example doesn't even need to be printf
, it could have been puts
.
If we want to talk about printf
versus alternatives, that's at a bit of a tangent to the serial work, but I guess the possibilities are:
- Using
printf
- Using
printf
withminimal-printf
on, reducing formatter - Only using
puts
(or all yourprintf
s are simple enough for compiler to turn them intoputs
), avoiding formatter - Using just
write
, avoiding C library altogether - Turning on
minimal-console
(in conjunction with any of the 4 previous options)
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.
I meant calling stdlib printf from the application, and it's a good point it's not a place to talk about memory optimisations. But I don't want to push people to printf too much.
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.
I changed should
into can
and put the example using write
first. Discussion related to printf comes after so I am not emphasing the use of printf.
|
||
### Detailed design : BufferedSerial | ||
|
||
`BufferedSerial` is `UARTSerial` renamed to convey the original purpose of the class. In addition, the new class will allow configurability of the transmit and receive buffer size so that each instance of the class can configure its buffer size according to its intended usage, for example a modem may need a large input buffer and a console may not need any input buffer. |
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.
The name reminds me earlier component available on developer page. It's been used, I recall the name UARTSerial was chosen not to create a naming clash.
I assume they are not compatible and users would need to update their apps if they move to this new class? Might be just noted here
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.
Indeed I can see references to a BufferedSerial class if I google it. But I don't think the class was even part of a Mbed OS release. Wouldn't it create even more confusion if we refer to a class not in Mbed OS source code?
As part of this work, we will deprecate Serial and RawSerial so users will get warnings if they use deprecated code (The BufferedSerial class publicly derived from RawSerial).
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.
It has been used mainly in mbed 2 apps. Correct, was not part of the release. Just wanted to make sure we are aware. It shall be fine as it is.
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.
LGTM
CI started |
Test run: FAILEDSummary: 2 of 12 test jobs failed Failed test jobs:
|
Restarted CI (some internal fault , I could not restart just 2 stages) |
Description
This is the design proposal for cleaning-up the serial class hierarchy.
Pull request type
Reviewers
@bulislaw @hugueskamba @kjbracey-arm
Release Notes