Skip to content

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

Merged
merged 1 commit into from
Nov 8, 2019
Merged

Serial design draft #11634

merged 1 commit into from
Nov 8, 2019

Conversation

evedon
Copy link
Contributor

@evedon evedon commented Oct 4, 2019

Description

This is the design proposal for cleaning-up the serial class hierarchy.

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[X] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@bulislaw @hugueskamba @kjbracey-arm

Release Notes

Copy link
Collaborator

@hugueskamba hugueskamba left a 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.

@ciarmcom ciarmcom requested review from bulislaw, hugueskamba, kjbracey and a team October 4, 2019 17:24
@ciarmcom
Copy link
Member

ciarmcom commented Oct 4, 2019

@evedon, thank you for your changes.
@bulislaw @kjbracey-arm @hugueskamba @ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

Copy link
Member

@bulislaw bulislaw left a 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.

@hugueskamba
Copy link
Collaborator

@evedon Are we missing a way to completely take out the re-targeting code if we do not need it?
How do I exclude the content of mbed_retarget.c if I am planning on using say UnbufferedSerial directly?

@kjbracey
Copy link
Contributor

Silly question - what's the simplest way to view this as a whole with diagrams?


![Retarget](./diagrams/retarget.png)

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.
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@kjbracey
Copy link
Contributor

@evedon Are we missing a way to completely take out the re-targeting code if we do not need it?
How do I exclude the content of mbed_retarget.c if I am planning on using say UnbufferedSerial directly?

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.

@kjbracey
Copy link
Contributor

This looks good, happy with almost all of it, main concern is about the value of MinimalSerial - would like to discuss a bit.

@hugueskamba
Copy link
Collaborator

hugueskamba commented Oct 17, 2019

Silly question - what's the simplest way to view this as a whole with diagrams?

@kjbracey-arm
Here: https://github.com/evedon/mbed-os/blob/serial_design/docs/design-documents/drivers/serial/serial.md

@evedon
Copy link
Contributor Author

evedon commented Oct 30, 2019

All points addressed and MinimalSerial removed as it did not bring memory saving. Please let me know if you have further comment.

@evedon
Copy link
Contributor Author

evedon commented Nov 1, 2019

Latest comments addressed in last commit. All commits squashed.

@kjbracey
Copy link
Contributor

kjbracey commented Nov 4, 2019

Couple more thoughts on default changes - I'm advocating for stdio-buffered-serial to default to true, but there are two other possible changes

  • stdio-convert-tty-newlines or stdio-convert-newlines to true. (I was pushing for this to be the case for 5.0, but didn't get it - there was a big "be compatible with Mbed 2" wish, kind of as a counterpoint to Mbed OS 3).
  • stdio-baud-rate to 115200.

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 \r\n I see in applications. All those \r take up ROM...

@evedon
Copy link
Contributor Author

evedon commented Nov 4, 2019

Couple more thoughts on default changes - I'm advocating for stdio-buffered-serial to default to true, but there are two other possible changes

  • stdio-convert-tty-newlines or stdio-convert-newlines to true. (I was pushing for this to be the case for 5.0, but didn't get it - there was a big "be compatible with Mbed 2" wish, kind of as a counterpoint to Mbed OS 3).
  • stdio-baud-rate to 115200.

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 \r\n I see in applications. All those \r take up ROM...

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 stdio-buffered-serial default to true.

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.

Copy link
Collaborator

@hugueskamba hugueskamba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@bulislaw bulislaw left a 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`.
Copy link
Member

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)

Copy link
Contributor

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 with minimal-printf on, reducing formatter
  • Only using puts (or all your printfs are simple enough for compiler to turn them into puts), avoiding formatter
  • Using just write, avoiding C library altogether
  • Turning on minimal-console (in conjunction with any of the 4 previous options)

Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 7, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Nov 7, 2019

Test run: FAILED

Summary: 2 of 12 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test
  • jenkins-ci/mbed-os-ci_exporter

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 8, 2019

Restarted CI (some internal fault , I could not restart just 2 stages)

@0xc0170 0xc0170 merged commit 6e6c7d0 into ARMmbed:master Nov 8, 2019
@0xc0170 0xc0170 added release-version: 5.15.0-rc1 and removed release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 labels Nov 19, 2019
@evedon evedon deleted the serial_design branch January 9, 2020 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants