-
Notifications
You must be signed in to change notification settings - Fork 3k
minimal-printf should not bypass the retargetting code #11235
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
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.
If making this change, it can be pared back more.
If print character is just fputc, then the "enable file" option is no longer needed - you can just always do fputc, and get rid of that option. (But you need to pass stdout
instead of NULL whereever you're passing NULL as stream?)
The "enable file" option can later be a thing that actually cuts that out at the retargetting layer, so fputc ignores its FILE parameter and just does a console write. Done there, it should be a bigger saving.
#define MBED_PRINT_CHARACTER(x) | ||
|
||
#endif // if DEVICE_SERIAL | ||
#define MBED_PRINT_CHARACTER(x) { fputc(x, stdout); } |
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.
Having done this, the CONSOLE_OUTPUT_UART
option no longer means that, and really the whole option should be removed (for now).
We already have the retargetting mechanisms to make fputc go to SingleWireOutput, so it isn't needed here.
In future there could be some system option to hardcode fputc globally to actually be a particular console type, cutting back the retargetting generally, but that option wouldn't be processed 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.
The mechanism in the retargetting code is via mbed_override_console which needs to be implemented by the application.
Althought it is simpler to have the option to output to SWO using a config option minimal-printf-console-output
as was done by the original minimal-printf library, I can remove this code for the sake of simplicity.
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.
If you want "easy-to-select SWO", it shouldn't be bound into the "minimal-printf" - the same easy-selection mechanism should be available with full retargetting.
You could have an option which does the override-console for you. In network interfaces we have such options done non-centrally as esp8266.provide-default
etc, which activates that particular WiFiInterface::get_default_instance
. SWO could have an option that makes it do that with mbed_override_console
.
(Often I'd expect a target to be selecting SWO, if that's the way the target's wired, not the application itself).
The hypothetical minimal-retargetting would have to have a parallel hardcoded-mechanism to pick up the known hardcoded retargets. Not sure what the implementation would look like, but it could certainly follow the easy-selection option, so that option just uses the generic mechanism with full retargetting, or selects a hardcoded thing in minimal retargetting.
@@ -1,12 +1,12 @@ | |||
{ | |||
"GCC_ARM": { | |||
"common": ["-DMBED_MINIMAL_PRINTF", "-fno-builtin-printf"], | |||
"common": ["-DMBED_MINIMAL_PRINTF"], |
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.
Why was this removed?
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.
Because the change is making printf work "normally", so the compiler no longer needs to treat it as "abnormal".
Without this option, the compiler can transform printf("Hello\n")
into puts("Hello")
, or printf(".")
into putchar('.')
. That would have triggered the problem we're now fixing.
Putting this option in meant output was consistent as long as the user always used printf
and never did puts
or putchar
themselves.
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.
Ok. I need to understand how that retarget work.
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's not so much about how the retargetting works in detail as the fact you're short-circuiting it
printf
, putchar
and puts
are all supposed to go to the same place as fputc(stdout)
.
If those things don't all go to the same place, or skip the buffering among only some paths, then things get weird when you mix them.
(The retargetting controls where fputc(stdout) goes, and then all other I/O calls follow).
The enable file option wraps fprintf & vfprintf so it is still useful. |
Okay, I'll need to double-check that a bit more - I was looking at the apparently-unneeded |
Okay, the enable file thing also controls "do we also send fprintf via minimal printf". Turning that on then activated the Again, simplifying One different potential saving I could see is eliminating the |
My last commit simpifies the logic around fputc.
I agree that we can remove the fputc dependency in mbed_minimal_putchar if only sprintf is called by the application but I would rather leave this for a different PR. |
@@ -128,10 +128,6 @@ | |||
"help": "Use the MPU if available to fault execution from RAM and writes to ROM. Can be disabled to reduce image size.", | |||
"value": true | |||
}, | |||
"minimal-printf-console-output": { |
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.
Should minimal-printf-enable-file-stream
also be removed given mbed_minimal_putchar
no longer considers it?
If it should be removed, references in mbed_printf.c/h
and mbed_printf_wrapper.c
also should be removed.
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.
ec7e232
to
be6413c
Compare
…etargetting code Removed minimal-printf-console-output
be6413c
to
d9f3263
Compare
This force push rebases from master and squashes all commits to fix issue #11234. |
CI started |
Job aborted, internal error, restarting |
Test run: FAILEDSummary: 2 of 4 test jobs failed Failed test jobs:
|
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
minimal-printf should not be trying to work around the retargetting - it should just use fputc.
Fixes #11234
Pull request type
Reviewers
@kjbracey-arm
Release Notes