Skip to content

Commit

Permalink
[opentitantool] HyperDebug driver robustness
Browse files Browse the repository at this point in the history
When the driver reads a command response from the HyperDebug text
console, it no longer relies on getting timeout to recognize when the
output is complete.  (Instead if it sees the prompt "> " as the final
two characters in any chunk received, it is all.)

With that in mind, there is no reason to have the timeout as low as
100ms.  In particular the `reinit` command executed as part of
"transport init" takes a little while to calibrate ADC and reset various
circuits in HyperDebug, and could get more responsiblities in the
future.  And on top of that, the USB bus introduces sometimes
unpredictable delays.

This CL increase the general delay for HyperDebug console response to 3
seconds.  And also propagates any error messages from `reinit` in a
slightly better way.

Change-Id: I3ecb17a3ad32f923b240d0dcce76e6d40938e4c8
Signed-off-by: Jes B. Klinke <[email protected]>
  • Loading branch information
jesultra committed Nov 14, 2024
1 parent 72642c0 commit c5d7047
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions sw/host/opentitanlib/src/transport/hyperdebug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ pub struct Conn {
impl MaintainConnection for Conn {}

impl Inner {
/// General timeout for response on the HyperDebug text-based USB command console.
const COMMAND_TIMEOUT: Duration = Duration::from_millis(3000);

/// Establish connection with HyperDebug console USB interface.
pub fn connect(&self) -> Result<Rc<Conn>> {
if let Some(conn) = self.conn.borrow().upgrade() {
Expand All @@ -462,7 +465,7 @@ impl Inner {
.to_str()
.ok_or(TransportError::UnicodePathError)?;
let port =
TTYPort::open(&serialport::new(port_name, 115_200).timeout(Duration::from_millis(100)))
TTYPort::open(&serialport::new(port_name, 115_200).timeout(Self::COMMAND_TIMEOUT))
.context("Failed to open HyperDebug console")?;
flock_serial(&port, port_name)?;
let conn = Rc::new(Conn {
Expand Down Expand Up @@ -642,7 +645,17 @@ impl<T: Flavor> Transport for Hyperdebug<T> {
}

fn apply_default_configuration(&self) -> Result<()> {
self.inner.cmd_no_output("reinit")
let mut error: Option<String> = None;
self.inner.execute_command("reinit", |line| {
log::warn!("Unexpected HyperDebug output: {}", line);
if line.starts_with("Error: ") {
error = Some(line.to_string());
}
})?;
if let Some(err) = error {
bail!(TransportError::CommunicationError(err));
}
Ok(())
}

// Create SPI Target instance, or return one from a cache of previously created instances.
Expand Down

0 comments on commit c5d7047

Please sign in to comment.