Repository: probe-rs/probe-rs
Pull request #2764 (2024-08-14 16:55:03)

Fix warnings printed during tests, poll less data for halted_access


Patch:
diff --git a/probe-rs/src/probe/espusbjtag/protocol.rs b/probe-rs/src/probe/espusbjtag/protocol.rs
index 3d74e5dd..7dd476a6 100644
--- a/probe-rs/src/probe/espusbjtag/protocol.rs
+++ b/probe-rs/src/probe/espusbjtag/protocol.rs
@@ -365,6 +365,12 @@ impl ProtocolHandler {
 
     /// Sends the commands stored in the output buffer to the USB EP.
     fn send_buffer(&mut self) -> Result<(), DebugProbeError> {
+        assert!(
+            self.output_buffer.len() <= OUT_BUFFER_SIZE,
+            "Output buffer too large: {} elements, max {OUT_BUFFER_SIZE}",
+            self.output_buffer.len()
+        );
+
         let mut commands = [0; OUT_EP_BUFFER_SIZE];
         for (out, byte) in commands
             .iter_mut()
@@ -382,6 +388,13 @@ impl ProtocolHandler {
 
         let len = (self.output_buffer.len() + 1) / 2;
 
+        assert!(
+            len <= commands.len(),
+            "Output buffer too large: {len} bytes ({} nibbles), max {}",
+            self.output_buffer.len(),
+            commands.len(),
+        );
+
         tracing::trace!(
             "Writing {} bytes ({} nibbles) to usb endpoint",
             len,
diff --git a/probe-rs/src/session.rs b/probe-rs/src/session.rs
index 46a94336..16f7942f 100644
--- a/probe-rs/src/session.rs
+++ b/probe-rs/src/session.rs
@@ -439,9 +439,9 @@ impl Session {
                 Err(Error::CoreDisabled(_)) => continue,
                 other => other?,
             };
-            let status = c.status()?;
-            tracing::debug!("Core {core} status: {:?}", status);
-            if !status.is_halted() {
+            if c.core_halted()? {
+                tracing::debug!("Core {core} already halted");
+            } else {
                 tracing::debug!("Halting core...");
                 resume_state.push(core);
                 c.halt(Duration::from_millis(100))?;
diff --git a/probe-rs/src/vendor/espressif/sequences/esp32s2.rs b/probe-rs/src/vendor/espressif/sequences/esp32s2.rs
index 302e4414..266fa147 100644
--- a/probe-rs/src/vendor/espressif/sequences/esp32s2.rs
+++ b/probe-rs/src/vendor/espressif/sequences/esp32s2.rs
@@ -165,10 +165,14 @@ impl XtensaDebugSequence for ESP32S2 {
 
         // Reset CPU
         match self.set_peri_reg_mask(core, Self::OPTIONS0, SYS_RESET, SYS_RESET) {
-            err @ Err(crate::Error::Xtensa(XtensaError::XdmError(xdm::Error::Xdm {
-                source: DebugRegisterError::Unexpected(_),
-                ..
-            }))) => {
+            err @ Err(crate::Error::Xtensa(XtensaError::XdmError(
+                xdm::Error::ExecOverrun
+                | xdm::Error::InstructionIgnored
+                | xdm::Error::Xdm {
+                    source: DebugRegisterError::Unexpected(_),
+                    ..
+                },
+            ))) => {
                 // ignore error
                 tracing::debug!("Error ignored: {err:?}");
             }


Test patch:
diff --git a/probe-rs-tools/src/bin/probe-rs/cmd/run/test_run_mode.rs b/probe-rs-tools/src/bin/probe-rs/cmd/run/test_run_mode.rs
index cf220d1d..767c928e 100644
--- a/probe-rs-tools/src/bin/probe-rs/cmd/run/test_run_mode.rs
+++ b/probe-rs-tools/src/bin/probe-rs/cmd/run/test_run_mode.rs
@@ -188,6 +188,12 @@ impl TestRunMode {
         tracing::info!("Running test {}", test.name);
         core.reset_and_halt(Duration::from_millis(100))
             .map_err(|e| anyhow::anyhow!(e))?;
+
+        session_and_runloop
+            .run_loop
+            .rtt_client
+            .clear_control_block(core)?;
+
         let timeout = test.timeout.map(|t| Duration::from_secs(t as u64));
         let timeout = timeout.unwrap_or(Duration::from_secs(60)); // TODO: make global timeout configurable: https://github.com/probe-rs/embedded-test/issues/3
         let mut cmdline_requested = false;