Skip to content

Commit 24b8169

Browse files
committed
feat(test_runner): pass a reference to the connected RP2040 test driver serial interface
As I feared, the serial driver discards any data received while the port is not opened. I need to add a mechanism to withhold the test driver's data transmission until the test runner gives a signal.
1 parent cddf56e commit 24b8169

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/r3_test_runner/src/targets/rp_pico.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
//! load a program.
1919
use anyhow::{anyhow, Context, Result};
2020
use std::future::Future;
21-
use tokio::{io::AsyncWriteExt, task::spawn_blocking, time::delay_for};
21+
use tokio::{
22+
io::{AsyncWriteExt, BufStream},
23+
task::spawn_blocking,
24+
time::delay_for,
25+
};
2226
use tokio_serial::{Serial, SerialPortSettings};
2327

24-
use super::{jlink::read_elf, Arch, DebugProbe, Target};
28+
use super::{demux::Demux, jlink::read_elf, Arch, DebugProbe, Target};
2529
use crate::utils::retry_on_fail_with_delay;
2630

2731
pub struct RaspberryPiPico;
@@ -72,7 +76,7 @@ impl Target for RaspberryPiPico {
7276
a PICOBOOT USB interface failed with the following error: {}",
7377
e
7478
);
75-
Some(serial)
79+
Some(BufStream::new(serial))
7680
}
7781
(Err(e), Ok(_picoboot_interface)) => {
7882
log::debug!(
@@ -111,7 +115,7 @@ struct RaspberryPiPicoUsbDebugProbe {
111115
/// Even if this field is set, the test driver's current state is
112116
/// indeterminate in general, so the target must be rebooted before doing
113117
/// anything meaningful.
114-
serial: Option<Serial>,
118+
serial: Option<BufStream<Serial>>,
115119
}
116120

117121
impl DebugProbe for RaspberryPiPicoUsbDebugProbe {
@@ -121,7 +125,10 @@ impl DebugProbe for RaspberryPiPicoUsbDebugProbe {
121125
) -> std::pin::Pin<Box<dyn Future<Output = Result<super::DynAsyncRead<'_>>> + '_>> {
122126
let exe = exe.to_owned();
123127
Box::pin(async move {
124-
if let Some(mut serial) = self.serial.take() {
128+
if let Some(serial) = self.serial.take() {
129+
// Discard any leftover data and unwrap `BufStream`
130+
let mut serial = serial.into_inner();
131+
125132
// Reboot the target into BOOTSEL mode. This will sever the
126133
// serial connection.
127134
log::debug!(
@@ -146,16 +153,15 @@ impl DebugProbe for RaspberryPiPicoUsbDebugProbe {
146153
// Wait until the host operating system recognizes the USB device...
147154
delay_for(DEFAULT_PAUSE).await;
148155

149-
self.serial = Some(
156+
let serial =
150157
retry_on_fail_with_delay(|| async { spawn_blocking(open_serial).await.unwrap() })
151158
.await
152-
.with_context(|| "Failed to connect to the test driver serial interface.")?,
153-
);
159+
.with_context(|| "Failed to connect to the test driver serial interface.")?;
154160

155-
// TODO: give a 'go' signal, grab the output,
156-
// and then issue a reboot request by sending `r`
161+
self.serial = Some(BufStream::new(serial));
157162

158-
todo!()
163+
// Now, pass the channel to the caller
164+
Ok(Box::pin(Demux::new(self.serial.as_mut().unwrap())) as _)
159165
})
160166
}
161167
}

0 commit comments

Comments
 (0)