-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Interface for alternative stdio retargeting #5356
Conversation
@sg- could you take a look |
stdio retargeting 👍 , @0x6d61726b thanks for the bringing this up with a proposal The default implementation should be the one that is currently used and a target needs to support. A question is how it should be provided? Can we find a better way than in this patch? Should there be an API for stdin/out, default implementation using mbed serial as it is now, the overriden by a config setting? |
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 dont care for the implementation but the concept is a good one. Where is the JLINK implementaiton? Not sure we'd want a stub without the debugger support.
Shall we move all the standard IO ops (or their actual backend implementation) to separate file implementing some set API and pull in specific implementation based on compile time flags? That would make it nicely abstracted and extensible (SWO?) and would get rid of all the ugly ifdefs. |
@sg- the sample implementation is here: 0x6d61726b/mbed-os-retarget-segger-rtt |
@bulislaw did you mean to request changes? @0x6d61726b Could you move all the standard IO ops to separate file as @bulislaw suggested? |
@theotherjimmy I don't know how it shall look like in the final implementation. Since I am not a firmware developement engineer, I may not be the right person for architecture changes. |
@0x6d61726b You created already declaration header file, this is 👍 . As quoted, if we can move those ifdef in the retarget file in this patch to own implementation (then retarget only invokes new API functions). One question is , can we add this segger implementation to the codebase? Having:
Would this make sense to have these stubs in place here and possible to use out of the box. |
Ok, I will work on that on the upcoming weekend
That is a question I cannot answer. It may also be a legal issue? |
I had a look at those files previously, they are released with 3-Clause BSD License so do not see a problem adding them. Let's first complete the API phase, and add the additional implementation right after |
You can always create a class that inherits from Stream and them implement a claim function making that call in mbed_main or a constructor if needed. https://os.mbed.com/users/Sissors/code/MODSERIAL/file/a3b2bc878529/MODSERIAL.cpp |
Can somebody explain why there should only one character being read at a time, please? |
I would assume that is a reason, serial_getc() reads only one character (no block read available) |
I would suggest adding SWO as one of the out of the box options. We already have CMSIS support for it: https://github.com/ARMmbed/mbed-os/blob/master/cmsis/TARGET_CORTEX_M/core_cm4.h#L2042-L2062 The only thing missing is the per platform initialization of the output pin and clock frequency. |
This is a major overlap with something I've been hoping to do a while, which is to allow stdin/stdout/stderr to be mapped to a normal At the minute it is advantageous to do
And use So I'm not sure we need to add a new special custom "FileHandle-lite" mechanism to retarget - it would make more sense to just let stdin/stdout/stderr be FileHandles, then users can implement FileHandle for whatever custom I/O device they have. Then that I/O device can be used either for stdout, or for any other manually-specified stream. You can implement |
I'm preparing a PR alternative to this which regularises the system, and should achieve the desired result more flexibly. The default raw A minimal FileHandle implementation is just |
See #5571 - @0x6d61726b, do you think that would serve your purpose? As it stands, your target would implement an |
Implemented FileHandle for SeggerRTT and registration of stdio according to discussion in ARMmbed/mbed-os#5356
@kjbracey-arm: I updated my sample implementation 0x6d61726b/mbed-os-retarget-segger-rtt with the functionality you implemented in #5571 and it works perfectly. |
Excellent! Good to see it worked for you. #5571 is still awaiting review though, so we'll have to see how that goes. Looking at your example, on the assumption that #5571 goes through as-is, it seems this is basically target-independent code, so you shouldn't be overriding Rather, as this is a somewhat-portable "support" library that apps can include, you should permit two ways of using it:
Then they can use both the serial and segger output.
Using Obviously apps could provide an Note that it's not worth checking the Another thing to be aware of - neither your original suggestion nor the #5571 override will redirect the output from |
@0x6d61726b, is it safe to say that this PR now depends on #5571, as per #5571 (comment) ? |
Automatic CI verification build not done, please verify manually. |
mbed_target_override_console replaced with mbed_override_console according to [comment from kjbracey-arm](ARMmbed/mbed-os#5356 (comment))
@0x6d61726b I think I misled you originally - I misunderstood that your code was going into some target-specific area, so told you to use the target override. |
@cmonr note that the code currently in the PR itself is standalone and not what we want because #5571 allows a different approach - @0x6d61726b has put the #5571-based version on a separate branch. @0x6d61726b - for your branch, please re-read my full proposal above. I don't think as it stands this is flexible enough - including the library automatically makes stdin/stdout go to SeggerRTT. While that's "easy", and maybe is a good default (and what your original did), there should still be a way to use this device separately without forcibly replacing the normal target stdout. #5571 makes that easy. |
#5571 has now been merged and will be in mbed OS 5.8 - is it okay to close this, and you will use that interface? |
@0x6d61726b Please reopen if its still relevant |
@kjbracey-arm Thanks a lot for merging it to mbed OS 5.8 - I will use that interface because it helps me a lot for debugging in custom hardware. I have already merged it into my local copy of OS 5.7 where it is in use. |
Description
This changes implement the
mbed_retarget_alt.h
interface that allows using an alternative/custom stdin/stdout/stderr interface other than the default serial port.By setting
MBED_CONF_RETARGET_STDIO_ALT = 1
the custom interface will be enabled.An example implementation can be found in the 0x6d61726b/mbed-os-retarget-segger-rtt repository.
Todos
Deploy notes
?
Steps to test or reproduce
The following test program can be used for testing general functionality:
Result (when typing
Hello World!.
):