Skip to content

Commit

Permalink
Add support for RTT through rust
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ committed Nov 11, 2024
1 parent e796e33 commit c27b9e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/platform/platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#if !defined(BOOTLOADER)
#include "sd_mmc/sd_mmc_start.h"
#endif
#include "rust/rust.h"

void platform_init(void)
{
oled_init();
#if !defined(BOOTLOADER)
rust_rtt_init();
sd_mmc_start();
#endif
}
15 changes: 13 additions & 2 deletions src/rust/bitbox02-rust-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#[macro_use]
extern crate std;

// include critical section implementation, needed by rtt-target
extern crate cortex_m;

use rtt_target::{debug_rprintln, debug_rtt_init_print};

// Since util_c defines an "alloc_error_handler" we get conflicts with std when testing
#[cfg(not(test))]
// for `format!`
Expand All @@ -36,14 +41,20 @@ mod sha2;
mod workflow;

// Whenever execution reaches somewhere it isn't supposed to rust code will "panic". Our panic
// handler will print the available information on the screen. If we compile with `panic=abort`
// handler will print the available information over RTT. If we compile with `panic=abort`
// this code will never get executed.
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
#[cfg_attr(feature = "bootloader", allow(unused_variables))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
#[cfg(feature = "firmware")]
bitbox02_rust::print_debug!(0, "Error: {}", info);
debug_rprintln!("{}", info);
loop {}
}

#[no_mangle]
pub extern "C" fn rust_rtt_init() {
debug_rtt_init_print!();
debug_rprintln!("rtt_init_print");
}

0 comments on commit c27b9e0

Please sign in to comment.