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

Add semihosting and SWO examples to mbed_override_console(). #10553

Merged
merged 2 commits into from May 23, 2019

Conversation

Projects
None yet
7 participants
@korjaa
Copy link
Contributor

commented May 10, 2019

Description

Add semihosting and SWO examples to mbed_override_console().

Pull request type

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

Reviewers

@kjbracey-arm

Release Notes

@korjaa

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2019

@TeroJaasko, here's the header update you suggested.

@korjaa korjaa force-pushed the korjaa:semihosting_docs branch from a6b8e58 to 3546a60 May 10, 2019

@korjaa

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2019

Added missing @endcode tags.

@ciarmcom ciarmcom requested review from kjbracey-arm and ARMmbed/mbed-os-maintainers May 10, 2019

@ciarmcom

This comment has been minimized.

Copy link
Member

commented May 10, 2019

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

@korjaa korjaa force-pushed the korjaa:semihosting_docs branch from 3546a60 to a48d126 May 10, 2019

@korjaa

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2019

Add missing fileno parameter name.

*
* Example using SingleWireOutput:
* @code
* FileHandle* mbed::mbed_override_console(int) {

This comment has been minimized.

Copy link
@kjbracey-arm

kjbracey-arm May 10, 2019

Contributor

Our coding standard changed while I was writing this in the first place, and the code got updated, but not the examples. * binds to the right. Fix the existing one too.

This comment has been minimized.

Copy link
@korjaa

korjaa May 23, 2019

Author Contributor

Stars are binding to the right now.

* static LocalFileSystem fs("host");
* if (fileno == STDIN_FILENO) {
* static FileHandle *in_terminal;
* static int in_open_result = fs.open(&in_terminal, ":tt", O_RDONLY);

This comment has been minimized.

Copy link
@kjbracey-arm

kjbracey-arm May 10, 2019

Contributor

That code is a bit RAM-inefficient, as it has two extra "once-only" control structures, and unused open results, but it's probably the simplest way of writing it.

The following would minimise RAM usage, but rather ends up obfuscating it.:

static LocalFileSystem fs("host");
struct TerminalStream {
    TerminalStream(FileSystemHandle &fs, int flags) {
        if (fs.open(&filehandle, ":tt", flags) != 0) {
            filehandle = NULL;
        }
    }
    FileHandle *filehandle;
}
if (fileno == STDIN_FILENO) {
    static TerminalStream in_terminal(fs, O_RDONLY):
    return in_terminal.filehandle;
} else {
    static TerminalStream out_terminal(fs, O_WRONLY);
    return out_terminal.filehandle;
}

You could leave it as-is; depends whether we want a simple example or to save 16 bytes of RAM when it's copy-pasted.

This comment has been minimized.

Copy link
@kjbracey-arm

kjbracey-arm May 10, 2019

Contributor

Another possible refinement would be to check if the debugger is attached before attempting the open (LocalFileSystem doesn't), so it doesn't crash.

semihost_connected() should tell you that in principle, but it seems that it's currently conditional on a DEVICE_DEBUG_AWARENESS that I've never heard of and is set on basically no platforms. Not sure why - it's a core CPU feature? All M-class devices should have the bit it's trying to check.

This comment has been minimized.

Copy link
@korjaa

korjaa May 23, 2019

Author Contributor

I think this one is so bluntly visible on the main.cpp, so maybe it would be OK to leave it as it is without the optimal memory consumption. And as you said it's a bit easier to understand.

This comment has been minimized.

Copy link
@korjaa

korjaa May 23, 2019

Author Contributor

This semihost_connected() sounds like a nice enhancement idea. Maybe this could be checked in some future commit when the DEVICE_DEBUG_AWARENESS is more common.

@bulislaw

This comment has been minimized.

Copy link
Member

commented May 10, 2019

We should have a section in our handbook about that as well.

@korjaa

This comment has been minimized.

Copy link
Contributor Author

commented May 13, 2019

We should have a section in our handbook about that as well.

@bulislaw You mean this one ARMmbed/mbed-os-5-docs#1063?

@0xc0170

This comment has been minimized.

Copy link
Member

commented May 22, 2019

@korjaa @kjbracey-arm How shall we proceed with this one, has not yet been approved.

@korjaa

This comment has been minimized.

Copy link
Contributor Author

commented May 23, 2019

I changed the stars and from my point of view this could be merged. @kjbracey-arm ?

@0xc0170

This comment has been minimized.

Copy link
Member

commented May 23, 2019

Ci started

@0xc0170 0xc0170 added needs: review and removed needs: work labels May 23, 2019

@mbed-ci

This comment has been minimized.

Copy link

commented May 23, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 removed the needs: review label May 23, 2019

@0xc0170 0xc0170 merged commit 541dee4 into ARMmbed:master May 23, 2019

26 checks passed

continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci/build-ARM Success
Details
jenkins-ci/build-GCC_ARM Success
Details
jenkins-ci/build-IAR Success
Details
jenkins-ci/cloud-client-test Success
Details
jenkins-ci/dynamic-memory-usage Success
Details
jenkins-ci/exporter Success
Details
jenkins-ci/greentea-test Success
Details
jenkins-ci/mbed2-build-ARM Success
Details
jenkins-ci/mbed2-build-GCC_ARM Success
Details
jenkins-ci/mbed2-build-IAR Success
Details
jenkins-ci/unittests Success
Details
travis-ci/astyle Success!
Details
travis-ci/docs Success!
Details
travis-ci/doxy-spellcheck Success!
Details
travis-ci/events Success! Runtime is 8521 cycles.
Details
travis-ci/gitattributestest Success!
Details
travis-ci/include_check Success!
Details
travis-ci/licence_check Success!
Details
travis-ci/littlefs Success! Code size is 8448B.
Details
travis-ci/psa-autogen Success!
Details
travis-ci/tools-py2.7 Success!
Details
travis-ci/tools-py3.5 Success!
Details
travis-ci/tools-py3.6 Success!
Details
travis-ci/tools-py3.7 Success!
Details

@korjaa korjaa deleted the korjaa:semihosting_docs branch May 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.