Skip to content

Output corrupted when using multiple rtt_target channels #981

@funmaker

Description

@funmaker

Hi. I am using defmt on top of rtt_target on esp32s3, launched by probe-rs. I am trying to set up multiple rtt channels, one for defmt and another for other information. However as soon as I declare the existence of another up channel in rtt_target::rtt_init! macro, defmt output seems corrupted.

My set up looks like this:

#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
    let mut channels = rtt_target::rtt_init! {
        up: {
            0: { size: 1024, mode: ChannelMode::NoBlockSkip, name: "Terminal" }
            1: { size: 1024, name: "Perf" }
        }
        down: {
            0: { size: 16, name: "Terminal" }
        }
    };
    
    rtt_target::set_defmt_channel(channels.up.0);

    defmt::info!("Hello from defmt.");
    channels.up.1.write(b"Hello from Channel 2\n");
}

Output looks like this:

[Brminal] ~~    ~
16:03:54.429: ~[Perf    ] Hello from Channel 2

But if I comment out the 2nd channel and 2nd print message, it all works as expected:

[INFO ] Hello from defmt.

I run probe-rs with:

$ probe-rs run --chip=esp32s3 --preverify --always-print-stacktrace --no-location --catch-hardfault /path/to/target/debug/program

Edit: it seems like there is some data race going on. Sometimes, the output works, sometimes not. Sometimes, adding seemingly noop code makes it work, and sometimes not. Eg adding if core::hint::black_box(1 == 0) { defmt::println!("{}", String::new()); } in some random function suddenly made it works, but then adding another line broke it again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions