Skip to content
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

mbed-retarget: Make filehandles optional to reduce code size #3

Closed

Conversation

hugueskamba
Copy link
Owner

@hugueskamba hugueskamba commented Sep 16, 2019

Description

The retarget code allocates an array of FileHandle* for console and file
handling (filehandles). A tiny target only needs a console (putc/getc).
There is no need for file handling.
The POSIX layer and the array of FileHandle* is not required for small
targets that only need a console ; this code should be optionally compiled
out if the configuration parameter platform.stdio-minimal-console-only is
selected instead of platform-stdio-buffered-serial.

See below sizes obtained with various configurations when building mbed-os-example-blinky with the following command line: mbed compile -t arm -m k64f

Use class UARTSerial
target.console-uart = true
platform.stdio-buffered-serial = true
platform.stdio-minimal-console-only = false

Total Static RAM memory (data + bss): 206958(+924) bytes
Total Flash memory (text + data): 52707(+3568) bytes

Use class DirectSerial
target.console-uart = true
platform.stdio-buffered-serial = false
platform.stdio-minimal-console-only = false

Total Static RAM memory (data + bss): 206034(-924) bytes
Total Flash memory (text + data): 49139(-3568) bytes

Use class MinimalSerial
target.console-uart = true
platform.stdio-buffered-serial = false
platform.stdio-minimal-console-only = true

Total Static RAM memory (data + bss): 205882(+0) bytes
Total Flash memory (text + data): 47641(+0) bytes

Use class Sink
target.console-uart = true
platform.stdio-buffered-serial = false
platform.stdio-minimal-console-only = true

Total Static RAM memory (data + bss): 205842(-360) bytes
Total Flash memory (text + data): 46633(-2522) bytes

Pull request type

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

Reviewers

Release Notes

@hugueskamba hugueskamba force-pushed the hk-optional-retarget-filehandles-iotcore-1322 branch from e2345e4 to 67815bc Compare September 16, 2019 17:53
@hugueskamba
Copy link
Owner Author

Some comments from Kevin:

Hugues Kamba 14:53
Hello Kevin,
Regarding making FileHandle optional in mbed_retarget.cpp, was the idea to access the serial interface with RawSerial::putc instead ?

Kevin Bracey 08:11
We want to make it possible to eliminate the run-time polymorphism (virtual FileHandle) and replace it with some sort of compile-time polymorphism.
As this is intentionally "minimal", can keep it simple, but still want to be overridable in principle.
Maybe a pair of functions minimal_console_putc, minimal_console_getc, with default WEAK definitions that just call serial_putc and serial_getc.

Kevin Bracey 08:18
(serial_getc won't work well, but it never has, and this is "minimal").
RawSerial was up for deprecation anyway in favour of DirectSerial which would have the FileHandle guff. It doesn't do much without it, may as well use serial HAL functions directly.

Kevin Bracey 08:20
Then it's just a series of #ifdef MINIMAL_CONSOLE changes inside write and read
A loop of minimal_console_putc instead of fhc->write.
And maybe MBED_ASSERT(fd == STDOUT_FILENO || fd == STDERR_FILENO) in write

Kevin Bracey 08:21
May as well put it in. If you wanted to Greentea test it, it needs to be there
(And Greentea copes with it being rubbish - the handshake means that the device is ready waiting in getc when the PC sends)
new messages
Although, no, hang on, Greentea isn't using the console stuff anyway
There's an open issue for that - it should be
It uses RawSerial directly
Other functions can be simplified - eg isatty will always be true if you don't have file support.
Hmm, maybe not the assert above - just leave it as an error check.
if (fildes != STDOUT_FILENO && fildes != STDERR_FILENO) return EBADF;
I think we don't need to be so minimal that we change the API of write - we can still return errors.

@hugueskamba hugueskamba force-pushed the hk-optional-retarget-filehandles-iotcore-1322 branch 14 times, most recently from fcde785 to 915583b Compare September 19, 2019 08:24
The retarget code allocates an array of FileHandle* for console and file
handling (filehandles). A tiny target only needs a console (putc/getc).
There is no need for file handling.
The POSIX layer and the array of FileHandle* is not required for small
targets that only need a console ; this code should be optionally compiled
out if the configuration parameter `platform.stdio-console-only` is
selected instead of `platform-stdio-buffered-serial`.
@hugueskamba hugueskamba force-pushed the hk-optional-retarget-filehandles-iotcore-1322 branch from 915583b to 47de453 Compare September 19, 2019 08:27
@hugueskamba hugueskamba force-pushed the hk-optional-retarget-filehandles-iotcore-1322 branch from 564ae22 to 25e9312 Compare September 23, 2019 06:53
@hugueskamba hugueskamba deleted the hk-optional-retarget-filehandles-iotcore-1322 branch November 18, 2019 15:09
hugueskamba pushed a commit that referenced this pull request Feb 5, 2020
Signed-off-by: PARKJIHOON <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant