Displaying something
Now that we have a running program, we would like to have one which displays something. Segger JLink tool suite can use the RTT protocol to exchange data between the host and the target. This protocol uses in-memory buffers that are scanned by the JLink debugging probe and transferred between the host and the target.
Using RTT on your board
Fortunately, several crates exist that implement the RTT protocol in Rust on the target side:
rtt-target
implements the RTT protocol and defines macros such asrprintln!()
to send formatted data to the hostpanic-rtt-target
implements a panic handler using RTT, so that you can see the full panic message on the host
❎ Add those two crates as dependencies.
❎ In src/main.rs
, remove your panic handler and import panic_rtt_target
so that its panic handler is linked in. Since we won't be using any symbol explicitly, we can import it silently:
use panic_rtt_target as _;
❎ Import the rtt_init_print
and rprintln
macros from rtt_target
. Modify the main program so that it uses them:
#[entry]
fn main() -> ! {
rtt_init_print!();
rprintln!("Hello, world!");
panic!("The program stopped");
}
❎ In a terminal, launch JLinkRTTClient
(or JLinkRTTClientExe
, depending on your setup). This is a simple client that connects to a running JLinkGDBServer
.
❎ Compile and run the program on the board using cargo run --release
. You should be able to see the output from the program.
Debugging will be much easier this way!