Skip to content

Commit 26228f6

Browse files
committed
Make down channel optional, based on disable-control-plane
1 parent ee92939 commit 26228f6

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/rtt_session.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ impl RttSession {
238238

239239
// Send the stop command if we can
240240
if let RttSessionState::Run(rtt_handles) = &self.state {
241-
if !self.rtt_cfg.disable_control_plane {
241+
if let Some(down_ch) = rtt_handles.down_channel.as_ref() {
242242
debug!("Sending stop command");
243243
let cmd = TrcCommand::StopTracing.to_wire_bytes();
244-
rtt_handles.down_channel.write(&mut core, &cmd).ok();
244+
down_ch.write(&mut core, &cmd).ok();
245245
}
246246
}
247247

@@ -512,24 +512,24 @@ impl RttSession {
512512
.position(|ch| ch.number() == self.rtt_cfg.up_channel as usize)
513513
.ok_or_else(|| Error::UpChannelInvalid(self.rtt_cfg.up_channel as _))?;
514514

515-
let down_ch_index = rtt
516-
.down_channels()
517-
.iter()
518-
.position(|ch| ch.number() == self.rtt_cfg.down_channel as usize)
519-
.ok_or_else(|| Error::DownChannelInvalid(self.rtt_cfg.down_channel as _))?;
520-
521515
let up_channel = rtt.up_channels.remove(up_ch_index);
522516
let up_channel_mode = up_channel.mode(&mut core)?;
523517
debug!(channel = up_channel.number(), mode = ?up_channel_mode, buffer_size = up_channel.buffer_size(), "Opened up channel");
524518

525-
let down_channel = rtt.down_channels.remove(down_ch_index);
526-
debug!(
527-
channel = down_channel.number(),
528-
buffer_size = down_channel.buffer_size(),
529-
"Opened down channel"
530-
);
519+
let down_channel = if !self.rtt_cfg.disable_control_plane {
520+
let down_ch_index = rtt
521+
.down_channels()
522+
.iter()
523+
.position(|ch| ch.number() == self.rtt_cfg.down_channel as usize)
524+
.ok_or_else(|| Error::DownChannelInvalid(self.rtt_cfg.down_channel as _))?;
525+
526+
let down_channel = rtt.down_channels.remove(down_ch_index);
527+
debug!(
528+
channel = down_channel.number(),
529+
buffer_size = down_channel.buffer_size(),
530+
"Opened down channel"
531+
);
531532

532-
if !self.rtt_cfg.disable_control_plane {
533533
if self.rtt_cfg.restart {
534534
debug!("Sending stop command");
535535
let cmd = TrcCommand::StopTracing.to_wire_bytes();
@@ -540,7 +540,11 @@ impl RttSession {
540540
debug!("Sending start command");
541541
let cmd = TrcCommand::StartTracing.to_wire_bytes();
542542
down_channel.write(&mut core, &cmd)?;
543-
}
543+
544+
Some(down_channel)
545+
} else {
546+
None
547+
};
544548

545549
// Auxilary cores get vector catching enabled after we know they're running
546550
if !self.target_cfg.bootloader && !self.target_cfg.bootloader_companion_application {
@@ -665,7 +669,7 @@ pub struct RttHandles {
665669
/// RTT up (target to host) channel
666670
up_channel: UpChannel,
667671
/// RTT down (host to target) channel
668-
down_channel: DownChannel,
672+
down_channel: Option<DownChannel>,
669673
}
670674

671675
#[derive(Debug)]

0 commit comments

Comments
 (0)