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

rust/src: add stdout print #1159

Merged
merged 1 commit into from
Jan 4, 2024
Merged

Conversation

asi345
Copy link
Collaborator

@asi345 asi345 commented Jan 4, 2024

Due to the cyclic dependency issues, rust part of the firmware can not import std create and therefore it does not have io capabilities, including 'println!'. As a result, C 'printf' function is exposed to rust as an external function.

It is a useful feature to have it because as
developers we may need to debug many parts of the
rust code when we are not using debuggers. Also,
in projects such as simulator, firmware is mainly
debugged with gdb. Hence there is limited flexibility of debugging when execution jumps to rust. In addition, simulator could print some of the ui elements of
firmware to stdout in this way.

@@ -176,6 +176,12 @@ pub fn reboot() -> ! {
panic!("reboot called")
}

pub fn print_stdout(msg: &str) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add #[cfg(feature = "testing")] to only activate this in tests, as this should not be used in production firmware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It must have slipped from my eye. Fixing.

Due to the cyclic dependency issues, rust part of the
firmware can not import std create and therefore it
does not have io capabilities, including 'println!'.
As a result, C 'printf' function is exposed to rust
as an external function.

It is a useful feature to have it because as
developers we may need to debug many parts of the
rust code when we are not using debuggers. Also,
in projects such as simulator, firmware is mainly
debugged with gdb. Hence there is limited flexibility
of debugging when execution jumps to rust. In addition,
simulator could print some of the ui elements of
firmware to stdout in this way.

Signed-off-by: asi345 <inanata15@gmail.com>
Copy link
Collaborator

@benma benma left a comment

Choose a reason for hiding this comment

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

utACK

@benma benma merged commit 1b954a6 into BitBoxSwiss:master Jan 4, 2024
1 check passed
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.

2 participants