Macro rtt_target::rtt_init[][src]

macro_rules! rtt_init {
    {
        $(up: { $($up:tt)* } )?
        $(down: { $($down:tt)* } )?
    } => { ... };
}

Initializes RTT with the specified channels. Channel numbers, buffer sizes and names can be defined.

The syntax looks as follows (note that commas are not allowed anywhere):

let channels = rtt_init! {
    up: {
        0: { // channel number
            size: 1024 // buffer size in bytes
            mode: NoBlockSkip // mode (optional, default: NoBlockSkip, see enum ChannelMode)
            name: "Terminal" // name (optional, default: no name)
        }
        1: {
            size: 32
        }
    }
    down: {
        0: {
            size: 16
            name: "Terminal"
        }
    }
};

The channel numbers must start from 0 and not skip any numbers, or otherwise odd things will happen. The order of the channel parameters is fixed, but optional parameters can be left out. This macro should be called once within a function, preferably close to the start of your entry point. The macro must only be called once - if it’s called twice in the same program a duplicate symbol error will occur.

At compile time the macro will statically reserve space for the RTT control block and the channel buffers. At runtime the macro fills in the structures and prepares them for use.

The macro returns a generate struct that contains the channels. The struct for the example above would look as follows:

struct Channels {
    up: (UpChannel, UpChannel),
    down: (DownChannel,),
}

The channels can either be accessed by reference or moved out as needed. For example:

use core::fmt::Write;

let channels = rtt_init! { ... };
let mut output = channels.up.0;
writeln!(output, "Hello, world!").ok();