From f1246fc8ab247720bc5da95bb000b571622aebef Mon Sep 17 00:00:00 2001 From: P-Storm Date: Tue, 29 Jul 2025 13:26:56 +0200 Subject: [PATCH 1/5] remote: Add get_target_voltage and use this in power argument --- src/bin/bmputil-cli.rs | 9 +++++++-- src/serial/remote/mod.rs | 1 + src/serial/remote/protocol_v0.rs | 31 +++++++++++++++++++++++++------ src/serial/remote/protocol_v1.rs | 4 ++++ src/serial/remote/protocol_v2.rs | 6 ++++-- src/serial/remote/protocol_v3.rs | 4 ++++ src/serial/remote/protocol_v4.rs | 4 ++++ 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/bin/bmputil-cli.rs b/src/bin/bmputil-cli.rs index f2338f7..7ebfc3d 100644 --- a/src/bin/bmputil-cli.rs +++ b/src/bin/bmputil-cli.rs @@ -438,10 +438,15 @@ fn power_command(cli_args: &CliArguments) -> Result<()> // Otherwise, turn the result set into a list and go through them displaying them let device = results.pop_single("power").map_err(|kind| kind.error())?; let remote = device.bmd_serial_interface()?.remote()?; + + match remote.get_target_power_state() { + Ok(power) => info!("Device target power state: {}", power), + Err(e) => warn!("Failed to retrieve target power state: {}", e), + }; - let power = remote.get_target_power_state()?; + let voltage = remote.get_target_voltage()?; + info!("Target voltage: {}V", voltage); - info!("Device target power state: {}", power); Ok(()) } diff --git a/src/serial/remote/mod.rs b/src/serial/remote/mod.rs index f08045d..c8ebde9 100644 --- a/src/serial/remote/mod.rs +++ b/src/serial/remote/mod.rs @@ -112,6 +112,7 @@ pub trait BmdRemoteProtocol fn supported_architectures(&self) -> Result>; fn supported_families(&self) -> Result>; fn get_target_power_state(&self) -> Result; + fn get_target_voltage(&self) -> Result; } /// Types implementing this trait provide raw SWD access to targets over the BMD remote protocol diff --git a/src/serial/remote/protocol_v0.rs b/src/serial/remote/protocol_v0.rs index 21d94d2..71110e9 100644 --- a/src/serial/remote/protocol_v0.rs +++ b/src/serial/remote/protocol_v0.rs @@ -3,16 +3,15 @@ // SPDX-FileContributor: Written by Rachel Mant use std::sync::{Arc, Mutex, MutexGuard}; - -use color_eyre::eyre::{Result, eyre}; +use color_eyre::eyre; +use color_eyre::eyre::{Result, eyre, OptionExt}; use log::{debug, warn}; use crate::serial::bmd_rsp::BmdRspInterface; use crate::serial::remote::adi::{AdiV5AccessPort, AdiV5DebugPort}; -use crate::serial::remote::{ - Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, - REMOTE_RESP_ERR, TargetAddr64, TargetArchitecture, TargetFamily, -}; +use crate::serial::remote::{Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, REMOTE_RESP_ERR, TargetAddr64, TargetArchitecture, TargetFamily, REMOTE_RESP_OK}; + +pub const REMOTE_TARGET_VOLTAGE: &str = "!GV#"; pub struct RemoteV0 { @@ -169,6 +168,22 @@ impl BmdRemoteProtocol for RemoteV0 { Err(eyre!("Not supported")) } + + fn get_target_voltage(&self) -> Result { + self.interface().buffer_write(REMOTE_TARGET_VOLTAGE)?; + let buffer = self.interface().buffer_read()?; + + if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + return Err(eyre!("Target voltage request failed")); + } + + if buffer.len() < 2 { + return Err(eyre!("Target voltage response is too short")); + } + + let value = buffer.get(1..buffer.len().saturating_sub(1)).expect("Should have some value"); + value.parse::().map_err(|e| eyre!("Can't parse target voltage value to a float, input {}, reason: {}", value, e) ) + } } impl From>> for RemoteV0Plus @@ -253,6 +268,10 @@ impl BmdRemoteProtocol for RemoteV0Plus { self.0.get_target_power_state() } + + fn get_target_voltage(&self) -> Result { + self.0.get_target_voltage() + } } impl From>> for RemoteV0JTAG diff --git a/src/serial/remote/protocol_v1.rs b/src/serial/remote/protocol_v1.rs index 8eb2a18..c4cf2f0 100644 --- a/src/serial/remote/protocol_v1.rs +++ b/src/serial/remote/protocol_v1.rs @@ -115,6 +115,10 @@ impl BmdRemoteProtocol for RemoteV1 { self.0.get_target_power_state() } + + fn get_target_voltage(&self) -> Result { + self.0.get_target_voltage() + } } impl From>> for RemoteV1ADIv5 diff --git a/src/serial/remote/protocol_v2.rs b/src/serial/remote/protocol_v2.rs index 5026f55..3495acd 100644 --- a/src/serial/remote/protocol_v2.rs +++ b/src/serial/remote/protocol_v2.rs @@ -21,8 +21,6 @@ pub struct RemoteV2JTAG(RemoteV0JTAG); const REMOTE_JTAG_INIT: &str = "!JS#"; /// This command asks the probe if the power is used -#[allow(dead_code)] -const REMOTE_TARGET_VOLTAGE: &str = "!GV#"; const REMOTE_GET_TARGET_POWER_STATE: &str = "!Gp#"; impl From>> for RemoteV2 @@ -139,6 +137,10 @@ impl BmdRemoteProtocol for RemoteV2 Ok(buffer.as_bytes()[1] == b'1') } + + fn get_target_voltage(&self) -> Result { + self.0.get_target_voltage() + } } impl From>> for RemoteV2JTAG diff --git a/src/serial/remote/protocol_v3.rs b/src/serial/remote/protocol_v3.rs index 9f4e68f..759f268 100644 --- a/src/serial/remote/protocol_v3.rs +++ b/src/serial/remote/protocol_v3.rs @@ -111,6 +111,10 @@ impl BmdRemoteProtocol for RemoteV3 { self.0.get_target_power_state() } + + fn get_target_voltage(&self) -> Result { + self.0.get_target_voltage() + } } impl From>> for RemoteV3ADIv5 diff --git a/src/serial/remote/protocol_v4.rs b/src/serial/remote/protocol_v4.rs index 2f6ce86..6b2ae7b 100644 --- a/src/serial/remote/protocol_v4.rs +++ b/src/serial/remote/protocol_v4.rs @@ -228,6 +228,10 @@ impl BmdRemoteProtocol for RemoteV4 { self.inner_protocol.get_target_power_state() } + + fn get_target_voltage(&self) -> Result { + self.inner_protocol.get_target_voltage() + } } impl From>> for RemoteV4ADIv5 From 65be5f7f802018a0144e56f8ac7cd054a482f8b7 Mon Sep 17 00:00:00 2001 From: P-Storm Date: Tue, 29 Jul 2025 15:21:27 +0200 Subject: [PATCH 2/5] remote: Added commands REMOTE_SRST_GET and REMOTE_PWR_GET --- src/bin/bmputil-cli.rs | 5 +-- src/serial/remote/mod.rs | 2 + src/serial/remote/protocol_v0.rs | 73 +++++++++++++++++++++++++++++--- src/serial/remote/protocol_v1.rs | 14 +++++- src/serial/remote/protocol_v2.rs | 14 +++++- src/serial/remote/protocol_v3.rs | 14 +++++- src/serial/remote/protocol_v4.rs | 14 +++++- 7 files changed, 123 insertions(+), 13 deletions(-) diff --git a/src/bin/bmputil-cli.rs b/src/bin/bmputil-cli.rs index 7ebfc3d..463b4a4 100644 --- a/src/bin/bmputil-cli.rs +++ b/src/bin/bmputil-cli.rs @@ -438,16 +438,15 @@ fn power_command(cli_args: &CliArguments) -> Result<()> // Otherwise, turn the result set into a list and go through them displaying them let device = results.pop_single("power").map_err(|kind| kind.error())?; let remote = device.bmd_serial_interface()?.remote()?; - + match remote.get_target_power_state() { Ok(power) => info!("Device target power state: {}", power), Err(e) => warn!("Failed to retrieve target power state: {}", e), - }; + }; let voltage = remote.get_target_voltage()?; info!("Target voltage: {}V", voltage); - Ok(()) } diff --git a/src/serial/remote/mod.rs b/src/serial/remote/mod.rs index c8ebde9..c0fc97f 100644 --- a/src/serial/remote/mod.rs +++ b/src/serial/remote/mod.rs @@ -113,6 +113,8 @@ pub trait BmdRemoteProtocol fn supported_families(&self) -> Result>; fn get_target_power_state(&self) -> Result; fn get_target_voltage(&self) -> Result; + fn get_srst_val(&self) -> Result; + fn get_target_supply_power(&self) -> Result; } /// Types implementing this trait provide raw SWD access to targets over the BMD remote protocol diff --git a/src/serial/remote/protocol_v0.rs b/src/serial/remote/protocol_v0.rs index 71110e9..f2e8c02 100644 --- a/src/serial/remote/protocol_v0.rs +++ b/src/serial/remote/protocol_v0.rs @@ -1,17 +1,30 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-FileCopyrightText: 2025 1BitSquared // SPDX-FileContributor: Written by Rachel Mant +// SPDX-FileContributor: Modified by P-Storm use std::sync::{Arc, Mutex, MutexGuard}; + use color_eyre::eyre; -use color_eyre::eyre::{Result, eyre, OptionExt}; +use color_eyre::eyre::{OptionExt, Result, eyre}; use log::{debug, warn}; use crate::serial::bmd_rsp::BmdRspInterface; use crate::serial::remote::adi::{AdiV5AccessPort, AdiV5DebugPort}; -use crate::serial::remote::{Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, REMOTE_RESP_ERR, TargetAddr64, TargetArchitecture, TargetFamily, REMOTE_RESP_OK}; +use crate::serial::remote::{ + Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, + REMOTE_RESP_ERR, REMOTE_RESP_OK, TargetAddr64, TargetArchitecture, TargetFamily, +}; pub const REMOTE_TARGET_VOLTAGE: &str = "!GV#"; +#[allow(dead_code)] +pub const REMOTE_SRST_SET: &str = "!GZ#"; +pub const REMOTE_SRST_GET: &str = "!Gz#"; +#[allow(dead_code)] +pub const REMOTE_PWR_SET: &str = "!GP#"; +pub const REMOTE_PWR_GET: &str = "!Gp#"; +#[allow(dead_code)] +pub const REMOTE_START: &str = "!GA#"; pub struct RemoteV0 { @@ -169,7 +182,8 @@ impl BmdRemoteProtocol for RemoteV0 Err(eyre!("Not supported")) } - fn get_target_voltage(&self) -> Result { + fn get_target_voltage(&self) -> Result + { self.interface().buffer_write(REMOTE_TARGET_VOLTAGE)?; let buffer = self.interface().buffer_read()?; @@ -181,8 +195,44 @@ impl BmdRemoteProtocol for RemoteV0 return Err(eyre!("Target voltage response is too short")); } - let value = buffer.get(1..buffer.len().saturating_sub(1)).expect("Should have some value"); - value.parse::().map_err(|e| eyre!("Can't parse target voltage value to a float, input {}, reason: {}", value, e) ) + let value = buffer + .get(1..buffer.len().saturating_sub(1)) + .expect("Should have some value"); + value + .parse::() + .map_err(|e| eyre!("Can't parse target voltage value to a float, input {}, reason: {}", value, e)) + } + + fn get_srst_val(&self) -> Result + { + self.interface().buffer_write(REMOTE_SRST_GET)?; + let buffer = self.interface().buffer_read()?; + + if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + return Err(eyre!("srst value request failed")); + } + + if buffer.len() < 2 { + return Err(eyre!("srst value response is too short")); + } + + Ok(buffer.as_bytes()[1] == b'1') + } + + fn get_target_supply_power(&self) -> Result + { + self.interface().buffer_write(REMOTE_PWR_GET)?; + let buffer = self.interface().buffer_read()?; + + if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + return Err(eyre!("remote_target_get_power value request failed")); + } + + if buffer.len() < 2 { + return Err(eyre!("remote_target_get_power value response is too short")); + } + + Ok(buffer.as_bytes()[1] == b'1') } } @@ -269,9 +319,20 @@ impl BmdRemoteProtocol for RemoteV0Plus self.0.get_target_power_state() } - fn get_target_voltage(&self) -> Result { + fn get_target_voltage(&self) -> Result + { self.0.get_target_voltage() } + + fn get_srst_val(&self) -> Result + { + self.0.get_srst_val() + } + + fn get_target_supply_power(&self) -> Result + { + self.0.get_target_supply_power() + } } impl From>> for RemoteV0JTAG diff --git a/src/serial/remote/protocol_v1.rs b/src/serial/remote/protocol_v1.rs index c4cf2f0..c0c815f 100644 --- a/src/serial/remote/protocol_v1.rs +++ b/src/serial/remote/protocol_v1.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-FileCopyrightText: 2025 1BitSquared // SPDX-FileContributor: Written by Rachel Mant +// SPDX-FileContributor: Modified by P-Storm use std::sync::{Arc, Mutex, MutexGuard}; @@ -116,9 +117,20 @@ impl BmdRemoteProtocol for RemoteV1 self.0.get_target_power_state() } - fn get_target_voltage(&self) -> Result { + fn get_target_voltage(&self) -> Result + { self.0.get_target_voltage() } + + fn get_srst_val(&self) -> Result + { + self.0.get_srst_val() + } + + fn get_target_supply_power(&self) -> Result + { + self.0.get_target_supply_power() + } } impl From>> for RemoteV1ADIv5 diff --git a/src/serial/remote/protocol_v2.rs b/src/serial/remote/protocol_v2.rs index 3495acd..62c765a 100644 --- a/src/serial/remote/protocol_v2.rs +++ b/src/serial/remote/protocol_v2.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-FileCopyrightText: 2025 1BitSquared // SPDX-FileContributor: Written by Rachel Mant +// SPDX-FileContributor: Modified by P-Storm use std::sync::{Arc, Mutex, MutexGuard}; @@ -138,9 +139,20 @@ impl BmdRemoteProtocol for RemoteV2 Ok(buffer.as_bytes()[1] == b'1') } - fn get_target_voltage(&self) -> Result { + fn get_target_voltage(&self) -> Result + { self.0.get_target_voltage() } + + fn get_srst_val(&self) -> Result + { + self.0.get_srst_val() + } + + fn get_target_supply_power(&self) -> Result + { + self.0.get_target_supply_power() + } } impl From>> for RemoteV2JTAG diff --git a/src/serial/remote/protocol_v3.rs b/src/serial/remote/protocol_v3.rs index 759f268..d141eab 100644 --- a/src/serial/remote/protocol_v3.rs +++ b/src/serial/remote/protocol_v3.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-FileCopyrightText: 2025 1BitSquared // SPDX-FileContributor: Written by Rachel Mant +// SPDX-FileContributor: Modified by P-Storm use std::sync::{Arc, Mutex, MutexGuard}; @@ -112,9 +113,20 @@ impl BmdRemoteProtocol for RemoteV3 self.0.get_target_power_state() } - fn get_target_voltage(&self) -> Result { + fn get_target_voltage(&self) -> Result + { self.0.get_target_voltage() } + + fn get_srst_val(&self) -> Result + { + self.0.get_srst_val() + } + + fn get_target_supply_power(&self) -> Result + { + self.0.get_target_supply_power() + } } impl From>> for RemoteV3ADIv5 diff --git a/src/serial/remote/protocol_v4.rs b/src/serial/remote/protocol_v4.rs index 6b2ae7b..9906c95 100644 --- a/src/serial/remote/protocol_v4.rs +++ b/src/serial/remote/protocol_v4.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-FileCopyrightText: 2025 1BitSquared // SPDX-FileContributor: Written by Rachel Mant +// SPDX-FileContributor: Modified by P-Storm use std::fmt::Display; use std::sync::{Arc, Mutex, MutexGuard}; @@ -229,9 +230,20 @@ impl BmdRemoteProtocol for RemoteV4 self.inner_protocol.get_target_power_state() } - fn get_target_voltage(&self) -> Result { + fn get_target_voltage(&self) -> Result + { self.inner_protocol.get_target_voltage() } + + fn get_srst_val(&self) -> Result + { + self.inner_protocol.get_srst_val() + } + + fn get_target_supply_power(&self) -> Result + { + self.inner_protocol.get_target_supply_power() + } } impl From>> for RemoteV4ADIv5 From 9fcb31bf22217fd8ba9396229aa365992a334b90 Mon Sep 17 00:00:00 2001 From: P-Storm Date: Tue, 29 Jul 2025 20:07:56 +0200 Subject: [PATCH 3/5] remote: Moved RemoteCommands into a struct and renamed SRST to NRST --- src/serial/remote/mod.rs | 16 ++++++++++++++++ src/serial/remote/protocol_v0.rs | 18 ++++-------------- src/serial/remote/protocol_v2.rs | 10 +++------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/serial/remote/mod.rs b/src/serial/remote/mod.rs index c0fc97f..2af96fa 100644 --- a/src/serial/remote/mod.rs +++ b/src/serial/remote/mod.rs @@ -25,6 +25,22 @@ mod protocol_v3; mod protocol_v4; pub mod riscv_debug; +pub struct RemoteCommands; + +#[allow(unused)] +impl RemoteCommands +{ + /// This command asks the probe if the power is used + pub const GET_TARGET_POWER_STATE: &'static str = "!Gp#"; + pub const JTAG_INIT: &'static str = "!JS#"; + pub const NRST_GET: &'static str = "!Gz#"; + pub const NRST_SET: &'static str = "!GZ#"; + pub const PWR_GET: &'static str = "!Gp#"; + pub const PWR_SET: &'static str = "!GP#"; + pub const START: &'static str = "!GA#"; + pub const TARGET_VOLTAGE: &'static str = "!GV#"; +} + /// This is the max possible size of a remote protocol packet which a hard limitation of the /// firmware on the probe - 1KiB is all the buffer that could be spared. pub const REMOTE_MAX_MSG_SIZE: usize = 1024; diff --git a/src/serial/remote/protocol_v0.rs b/src/serial/remote/protocol_v0.rs index f2e8c02..00c3d17 100644 --- a/src/serial/remote/protocol_v0.rs +++ b/src/serial/remote/protocol_v0.rs @@ -13,19 +13,9 @@ use crate::serial::bmd_rsp::BmdRspInterface; use crate::serial::remote::adi::{AdiV5AccessPort, AdiV5DebugPort}; use crate::serial::remote::{ Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, - REMOTE_RESP_ERR, REMOTE_RESP_OK, TargetAddr64, TargetArchitecture, TargetFamily, + REMOTE_RESP_ERR, REMOTE_RESP_OK, RemoteCommands, TargetAddr64, TargetArchitecture, TargetFamily, }; -pub const REMOTE_TARGET_VOLTAGE: &str = "!GV#"; -#[allow(dead_code)] -pub const REMOTE_SRST_SET: &str = "!GZ#"; -pub const REMOTE_SRST_GET: &str = "!Gz#"; -#[allow(dead_code)] -pub const REMOTE_PWR_SET: &str = "!GP#"; -pub const REMOTE_PWR_GET: &str = "!Gp#"; -#[allow(dead_code)] -pub const REMOTE_START: &str = "!GA#"; - pub struct RemoteV0 { interface: Arc>, @@ -184,7 +174,7 @@ impl BmdRemoteProtocol for RemoteV0 fn get_target_voltage(&self) -> Result { - self.interface().buffer_write(REMOTE_TARGET_VOLTAGE)?; + self.interface().buffer_write(RemoteCommands::TARGET_VOLTAGE)?; let buffer = self.interface().buffer_read()?; if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { @@ -205,7 +195,7 @@ impl BmdRemoteProtocol for RemoteV0 fn get_srst_val(&self) -> Result { - self.interface().buffer_write(REMOTE_SRST_GET)?; + self.interface().buffer_write(RemoteCommands::NRST_GET)?; let buffer = self.interface().buffer_read()?; if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { @@ -221,7 +211,7 @@ impl BmdRemoteProtocol for RemoteV0 fn get_target_supply_power(&self) -> Result { - self.interface().buffer_write(REMOTE_PWR_GET)?; + self.interface().buffer_write(RemoteCommands::PWR_GET)?; let buffer = self.interface().buffer_read()?; if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { diff --git a/src/serial/remote/protocol_v2.rs b/src/serial/remote/protocol_v2.rs index 62c765a..7e5801e 100644 --- a/src/serial/remote/protocol_v2.rs +++ b/src/serial/remote/protocol_v2.rs @@ -13,17 +13,13 @@ use crate::serial::remote::protocol_v0::RemoteV0JTAG; use crate::serial::remote::protocol_v1::RemoteV1; use crate::serial::remote::{ BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, REMOTE_RESP_ERR, - REMOTE_RESP_OK, TargetArchitecture, TargetFamily, + REMOTE_RESP_OK, RemoteCommands, TargetArchitecture, TargetFamily, }; pub struct RemoteV2(RemoteV1); pub struct RemoteV2JTAG(RemoteV0JTAG); -const REMOTE_JTAG_INIT: &str = "!JS#"; -/// This command asks the probe if the power is used -const REMOTE_GET_TARGET_POWER_STATE: &str = "!Gp#"; - impl From>> for RemoteV2 { fn from(interface: Arc>) -> Self @@ -57,7 +53,7 @@ impl BmdRemoteProtocol for RemoteV2 { // Try to have the probe initialise JTAG comms to any connected targets debug!("Remote JTAG init"); - self.interface().buffer_write(REMOTE_JTAG_INIT)?; + self.interface().buffer_write(RemoteCommands::JTAG_INIT)?; let buffer = self.interface().buffer_read()?; // If that failed for some reason, report it and abort if buffer.is_empty() || buffer.as_bytes()[0] == REMOTE_RESP_ERR { @@ -125,7 +121,7 @@ impl BmdRemoteProtocol for RemoteV2 fn get_target_power_state(&self) -> Result { - self.interface().buffer_write(REMOTE_GET_TARGET_POWER_STATE)?; + self.interface().buffer_write(RemoteCommands::GET_TARGET_POWER_STATE)?; let buffer = self.interface().buffer_read()?; if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { From 40f82b4cda88006e61ce92afdedddffb5463a763 Mon Sep 17 00:00:00 2001 From: P-Storm Date: Wed, 30 Jul 2025 15:02:20 +0200 Subject: [PATCH 4/5] remote: RemoteCommands cleanup & Code review --- src/bin/bmputil-cli.rs | 2 +- src/serial/bmd_rsp.rs | 109 +++++++++++++++++-------------- src/serial/remote/mod.rs | 65 ++++++++++-------- src/serial/remote/protocol_v0.rs | 51 +++++---------- src/serial/remote/protocol_v1.rs | 13 ++-- src/serial/remote/protocol_v2.rs | 21 +++--- src/serial/remote/protocol_v3.rs | 13 ++-- src/serial/remote/protocol_v4.rs | 29 ++++---- 8 files changed, 142 insertions(+), 161 deletions(-) diff --git a/src/bin/bmputil-cli.rs b/src/bin/bmputil-cli.rs index 463b4a4..4e90f53 100644 --- a/src/bin/bmputil-cli.rs +++ b/src/bin/bmputil-cli.rs @@ -444,7 +444,7 @@ fn power_command(cli_args: &CliArguments) -> Result<()> Err(e) => warn!("Failed to retrieve target power state: {}", e), }; - let voltage = remote.get_target_voltage()?; + let voltage = remote.get_nrst_voltage()?; info!("Target voltage: {}V", voltage); Ok(()) diff --git a/src/serial/bmd_rsp.rs b/src/serial/bmd_rsp.rs index 08bf5b2..bfc0af5 100644 --- a/src/serial/bmd_rsp.rs +++ b/src/serial/bmd_rsp.rs @@ -18,14 +18,11 @@ pub struct BmdRspInterface handle: File, protocol_version: ProtocolVersion, - read_buffer: [u8; REMOTE_MAX_MSG_SIZE], + read_buffer: [u8; RemoteResponse::MAX_MSG_SIZE], read_buffer_fullness: usize, read_buffer_offset: usize, } -const REMOTE_START: &str = "+#!GA#"; -const REMOTE_HL_CHECK: &str = "!HC#"; - impl BmdRspInterface { pub fn from_path(serial_port: &Path) -> Result @@ -35,7 +32,7 @@ impl BmdRspInterface let handle = File::options().read(true).write(true).open(serial_port)?; // Construct an interface object - let mut result = Self { + let mut interface = Self { handle, // We start out by not knowing what version of protocol the probe talks protocol_version: ProtocolVersion::Unknown, @@ -44,20 +41,66 @@ impl BmdRspInterface // probe responses, being mindful that there's no good way to find out // how much data is waiting for us from the probe, so it's this or use // a read call a byte, which is extremely expensive! - read_buffer: [0; REMOTE_MAX_MSG_SIZE], + read_buffer: [0; RemoteResponse::MAX_MSG_SIZE], read_buffer_fullness: 0, read_buffer_offset: 0, }; // Call the OS-specific handle configuration function to ready // the interface handle for use with the remote serial protocol - result.init_handle()?; + interface.init_handle()?; // Start remote protocol communications with the probe - result.buffer_write(REMOTE_START)?; - let buffer = result.buffer_read()?; + Self::start_probe_communication(&mut interface)?; + + // Next, ask the probe for its protocol version number. + // For historical reasons this is part of the "high level" protocol set, but is + // actually a general request. + interface.protocol_version = Self::protocol_version(&mut interface)?; + trace!("Probe talks BMD RSP {}", interface.protocol_version); + + // Now the object is ready to go, return it to the caller + Ok(interface) + } + + fn protocol_version(interface: &mut BmdRspInterface) -> Result + { + interface.buffer_write(RemoteCommands::HL_CHECK)?; + let buffer = interface.buffer_read()?; + + // Check for communication failures, it should respond with at least 1 character + let (first, rest) = buffer + .split_at_checked(1) + .ok_or_else(|| eyre!("Probe failed to respond at all to protocol version request"))?; + + match (first.as_bytes()[0], rest) { + // If the request failed by way of a not implemented response, we're on a v0 protocol probe + (RemoteResponse::RESP_NOTSUP, _) => Ok(ProtocolVersion::V0), + (RemoteResponse::RESP_OK, rest) => { + // Parse out the version number from the response + let version = decode_response(&rest, 8); + // Then decode/translate that to a protocol version enum value + match version { + // Protocol version number 0 coresponds to an enchanced v0 probe protocol ("v0+") + 0 => Ok(ProtocolVersion::V0Plus), + 1 => Ok(ProtocolVersion::V1), + 2 => Ok(ProtocolVersion::V2), + 3 => Ok(ProtocolVersion::V3), + 4 => Ok(ProtocolVersion::V4), + _ => Err(eyre!("Unknown remote protocol version {}", version)), + } + }, + // If the probe responded with anything other than OK or not supported, we're done + _ => Err(eyre!("Probe responded improperly to protocol version request with {}", buffer)), + } + } + + fn start_probe_communication(interface: &mut BmdRspInterface) -> Result<()> + { + interface.buffer_write(RemoteCommands::START)?; + let buffer = interface.buffer_read()?; // Check if that failed for any reason - if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::RESP_OK { let message = if buffer.len() > 1 { &buffer[1..] } else { @@ -66,41 +109,9 @@ impl BmdRspInterface return Err(eyre!("Remote protocol startup failed, error {}", message)); } // It did not, grand - we now have the firmware version string, so log it - debug!("Remote is {}", &buffer[1..]); - - // Next, ask the probe for its protocol version number. - // For historical reasons this is part of the "high level" protocol set, but is - // actually a general request. - result.buffer_write(REMOTE_HL_CHECK)?; - let buffer = result.buffer_read()?; - // Check for communication failures - if buffer.is_empty() { - return Err(eyre!("Probe failed to respond at all to protocol version request")); - } else if buffer.as_bytes()[0] != REMOTE_RESP_OK && buffer.as_bytes()[0] != REMOTE_RESP_NOTSUP { - // If the probe responded with anything other than OK or not supported, we're done - return Err(eyre!("Probe responded improperly to protocol version request with {}", buffer)); - } - // If the request failed by way of a not implemented response, we're on a v0 protocol probe - if buffer.as_bytes()[0] == REMOTE_RESP_NOTSUP { - result.protocol_version = ProtocolVersion::V0; - } else { - // Parse out the version number from the response - let version = decode_response(&buffer[1..], 8); - // Then decode/translate that to a protocol version enum value - result.protocol_version = match version { - // Protocol version number 0 coresponds to an enchanced v0 probe protocol ("v0+") - 0 => ProtocolVersion::V0Plus, - 1 => ProtocolVersion::V1, - 2 => ProtocolVersion::V2, - 3 => ProtocolVersion::V3, - 4 => ProtocolVersion::V4, - _ => return Err(eyre!("Unknown remote protocol version {}", version)), - }; - } - trace!("Probe talks BMD RSP {}", result.protocol_version); - - // Now the object is ready to go, return it to the caller - Ok(result) + let firmware_version = &buffer[1..]; + debug!("Remote is {}", firmware_version); + Ok(()) } /// Extract the remote protocol object to use to talk with this probe @@ -124,7 +135,7 @@ impl BmdRspInterface { // First drain the buffer till we see a start-of-response byte let mut response = 0; - while response != REMOTE_RESP { + while response != RemoteResponse::RESP { if self.read_buffer_offset == self.read_buffer_fullness { self.read_more_data()?; } @@ -133,7 +144,7 @@ impl BmdRspInterface } // Now collect the response - let mut buffer = [0u8; REMOTE_MAX_MSG_SIZE]; + let mut buffer = [0u8; RemoteResponse::MAX_MSG_SIZE]; let mut offset = 0; while offset < buffer.len() { // Check if we need more data or should use what's in the buffer already @@ -145,7 +156,7 @@ impl BmdRspInterface while self.read_buffer_offset + response_length < self.read_buffer_fullness && offset + response_length < buffer.len() { - if self.read_buffer[self.read_buffer_offset + response_length] == REMOTE_EOM { + if self.read_buffer[self.read_buffer_offset + response_length] == RemoteResponse::EOM { response_length += 1; break; } @@ -158,7 +169,7 @@ impl BmdRspInterface self.read_buffer_offset += response_length; offset += response_length - 1; // If this was because of REMOTE_EOM, return - if buffer[offset] == REMOTE_EOM { + if buffer[offset] == RemoteResponse::EOM { buffer[offset] = 0; let result = unsafe { String::from_utf8_unchecked(buffer[..offset].to_vec()) }; debug!("BMD RSP read: {}", result); diff --git a/src/serial/remote/mod.rs b/src/serial/remote/mod.rs index 2af96fa..326601e 100644 --- a/src/serial/remote/mod.rs +++ b/src/serial/remote/mod.rs @@ -27,39 +27,47 @@ pub mod riscv_debug; pub struct RemoteCommands; -#[allow(unused)] impl RemoteCommands { - /// This command asks the probe if the power is used + /// This command asks the probe if the reset pin is on + pub const GET_NRST: &'static str = "!Gz#"; + /// This command asks the probe if power is being supplied to the target pub const GET_TARGET_POWER_STATE: &'static str = "!Gp#"; + /// This command asks the probe what it's protocol version is + pub const HL_CHECK: &'static str = "!HC#"; + /// This command asks the probe to initialise JTAG comms to any connected targets pub const JTAG_INIT: &'static str = "!JS#"; - pub const NRST_GET: &'static str = "!Gz#"; - pub const NRST_SET: &'static str = "!GZ#"; - pub const PWR_GET: &'static str = "!Gp#"; - pub const PWR_SET: &'static str = "!GP#"; - pub const START: &'static str = "!GA#"; - pub const TARGET_VOLTAGE: &'static str = "!GV#"; + pub const NRST_TARGET_VOLTAGE: &'static str = "!GV#"; + /// This command asks the probe to the reset pin state + pub const SET_NRST: &'static str = "!GZ#"; + /// This command asks the probe to set the power state to the target + pub const SET_TARGET_POWER_STATE: &'static str = "!GP#"; + /// This command asks to start remote protocol communications with the probe + pub const START: &'static str = "+#!GA#"; } -/// This is the max possible size of a remote protocol packet which a hard limitation of the -/// firmware on the probe - 1KiB is all the buffer that could be spared. -pub const REMOTE_MAX_MSG_SIZE: usize = 1024; - -/// Start of message marker for the protocol -pub const REMOTE_SOM: u8 = b'!'; -/// End of message marker for the protocol -pub const REMOTE_EOM: u8 = b'#'; -/// Response marker for the protocol -pub const REMOTE_RESP: u8 = b'&'; +pub struct RemoteResponse; -/// Probe response was okay and the data returned is valid -pub const REMOTE_RESP_OK: u8 = b'K'; -/// Probe found an error with a request parameter -pub const REMOTE_RESP_PARERR: u8 = b'P'; -/// Probe encountered an error executing the request -pub const REMOTE_RESP_ERR: u8 = b'E'; -/// Probe does not support the request made -pub const REMOTE_RESP_NOTSUP: u8 = b'N'; +impl RemoteResponse +{ + /// End of message marker for the protocol + pub const EOM: u8 = b'#'; + /// This is the max possible size of a remote protocol packet which a hard limitation of the + /// firmware on the probe - 1KiB is all the buffer that could be spared. + pub const MAX_MSG_SIZE: usize = 1024; + /// Response marker for the protocol + pub const RESP: u8 = b'&'; + /// Probe encountered an error executing the request + pub const RESP_ERR: u8 = b'E'; + /// Probe does not support the request made + pub const RESP_NOTSUP: u8 = b'N'; + /// Probe response was okay and the data returned is valid + pub const RESP_OK: u8 = b'K'; + /// Probe found an error with a request parameter + pub const RESP_PARERR: u8 = b'P'; + /// Start of message marker for the protocol + pub const SOM: u8 = b'!'; +} pub type TargetAddr32 = u32; pub type TargetAddr64 = u64; @@ -128,9 +136,8 @@ pub trait BmdRemoteProtocol fn supported_architectures(&self) -> Result>; fn supported_families(&self) -> Result>; fn get_target_power_state(&self) -> Result; - fn get_target_voltage(&self) -> Result; - fn get_srst_val(&self) -> Result; - fn get_target_supply_power(&self) -> Result; + fn get_nrst_voltage(&self) -> Result; + fn get_nrst_val(&self) -> Result; } /// Types implementing this trait provide raw SWD access to targets over the BMD remote protocol diff --git a/src/serial/remote/protocol_v0.rs b/src/serial/remote/protocol_v0.rs index 00c3d17..4d5dede 100644 --- a/src/serial/remote/protocol_v0.rs +++ b/src/serial/remote/protocol_v0.rs @@ -5,15 +5,14 @@ use std::sync::{Arc, Mutex, MutexGuard}; -use color_eyre::eyre; -use color_eyre::eyre::{OptionExt, Result, eyre}; +use color_eyre::eyre::{Result, eyre}; use log::{debug, warn}; use crate::serial::bmd_rsp::BmdRspInterface; use crate::serial::remote::adi::{AdiV5AccessPort, AdiV5DebugPort}; use crate::serial::remote::{ Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, - REMOTE_RESP_ERR, REMOTE_RESP_OK, RemoteCommands, TargetAddr64, TargetArchitecture, TargetFamily, + RemoteCommands, RemoteResponse, TargetAddr64, TargetArchitecture, TargetFamily, }; pub struct RemoteV0 @@ -85,7 +84,7 @@ impl BmdRemoteProtocol for RemoteV0 self.interface().buffer_write(REMOTE_JTAG_INIT)?; let buffer = self.interface().buffer_read()?; // If that failed for some reason, report it and abort - if buffer.is_empty() || buffer.as_bytes()[0] == REMOTE_RESP_ERR { + if buffer.is_empty() || buffer.as_bytes()[0] == RemoteResponse::RESP_ERR { let message = if buffer.len() > 1 { &buffer[1..] } else { @@ -104,7 +103,7 @@ impl BmdRemoteProtocol for RemoteV0 self.interface().buffer_write(REMOTE_SWD_INIT)?; let buffer = self.interface().buffer_read()?; // If that failed for some reason, report it and abort - if buffer.is_empty() || buffer.as_bytes()[0] == REMOTE_RESP_ERR { + if buffer.is_empty() || buffer.as_bytes()[0] == RemoteResponse::RESP_ERR { let message = if buffer.len() > 1 { &buffer[1..] } else { @@ -172,12 +171,12 @@ impl BmdRemoteProtocol for RemoteV0 Err(eyre!("Not supported")) } - fn get_target_voltage(&self) -> Result + fn get_nrst_voltage(&self) -> Result { - self.interface().buffer_write(RemoteCommands::TARGET_VOLTAGE)?; + self.interface().buffer_write(RemoteCommands::NRST_TARGET_VOLTAGE)?; let buffer = self.interface().buffer_read()?; - if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::RESP_OK { return Err(eyre!("Target voltage request failed")); } @@ -188,17 +187,18 @@ impl BmdRemoteProtocol for RemoteV0 let value = buffer .get(1..buffer.len().saturating_sub(1)) .expect("Should have some value"); + value .parse::() .map_err(|e| eyre!("Can't parse target voltage value to a float, input {}, reason: {}", value, e)) } - fn get_srst_val(&self) -> Result + fn get_nrst_val(&self) -> Result { - self.interface().buffer_write(RemoteCommands::NRST_GET)?; + self.interface().buffer_write(RemoteCommands::GET_NRST)?; let buffer = self.interface().buffer_read()?; - if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::RESP_OK { return Err(eyre!("srst value request failed")); } @@ -208,22 +208,6 @@ impl BmdRemoteProtocol for RemoteV0 Ok(buffer.as_bytes()[1] == b'1') } - - fn get_target_supply_power(&self) -> Result - { - self.interface().buffer_write(RemoteCommands::PWR_GET)?; - let buffer = self.interface().buffer_read()?; - - if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { - return Err(eyre!("remote_target_get_power value request failed")); - } - - if buffer.len() < 2 { - return Err(eyre!("remote_target_get_power value response is too short")); - } - - Ok(buffer.as_bytes()[1] == b'1') - } } impl From>> for RemoteV0Plus @@ -309,19 +293,14 @@ impl BmdRemoteProtocol for RemoteV0Plus self.0.get_target_power_state() } - fn get_target_voltage(&self) -> Result - { - self.0.get_target_voltage() - } - - fn get_srst_val(&self) -> Result + fn get_nrst_voltage(&self) -> Result { - self.0.get_srst_val() + self.0.get_nrst_voltage() } - fn get_target_supply_power(&self) -> Result + fn get_nrst_val(&self) -> Result { - self.0.get_target_supply_power() + self.0.get_nrst_val() } } diff --git a/src/serial/remote/protocol_v1.rs b/src/serial/remote/protocol_v1.rs index c0c815f..67c1340 100644 --- a/src/serial/remote/protocol_v1.rs +++ b/src/serial/remote/protocol_v1.rs @@ -117,19 +117,14 @@ impl BmdRemoteProtocol for RemoteV1 self.0.get_target_power_state() } - fn get_target_voltage(&self) -> Result + fn get_nrst_voltage(&self) -> Result { - self.0.get_target_voltage() + self.0.get_nrst_voltage() } - fn get_srst_val(&self) -> Result + fn get_nrst_val(&self) -> Result { - self.0.get_srst_val() - } - - fn get_target_supply_power(&self) -> Result - { - self.0.get_target_supply_power() + self.0.get_nrst_val() } } diff --git a/src/serial/remote/protocol_v2.rs b/src/serial/remote/protocol_v2.rs index 7e5801e..c771803 100644 --- a/src/serial/remote/protocol_v2.rs +++ b/src/serial/remote/protocol_v2.rs @@ -12,8 +12,8 @@ use crate::serial::bmd_rsp::BmdRspInterface; use crate::serial::remote::protocol_v0::RemoteV0JTAG; use crate::serial::remote::protocol_v1::RemoteV1; use crate::serial::remote::{ - BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, REMOTE_RESP_ERR, - REMOTE_RESP_OK, RemoteCommands, TargetArchitecture, TargetFamily, + BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, RemoteCommands, + RemoteResponse, TargetArchitecture, TargetFamily, }; pub struct RemoteV2(RemoteV1); @@ -56,7 +56,7 @@ impl BmdRemoteProtocol for RemoteV2 self.interface().buffer_write(RemoteCommands::JTAG_INIT)?; let buffer = self.interface().buffer_read()?; // If that failed for some reason, report it and abort - if buffer.is_empty() || buffer.as_bytes()[0] == REMOTE_RESP_ERR { + if buffer.is_empty() || buffer.as_bytes()[0] == RemoteResponse::RESP_ERR { let message = if buffer.len() > 1 { &buffer[1..] } else { @@ -124,7 +124,7 @@ impl BmdRemoteProtocol for RemoteV2 self.interface().buffer_write(RemoteCommands::GET_TARGET_POWER_STATE)?; let buffer = self.interface().buffer_read()?; - if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::RESP_OK { return Err(eyre!("Supported current powered request failed")); } @@ -135,19 +135,14 @@ impl BmdRemoteProtocol for RemoteV2 Ok(buffer.as_bytes()[1] == b'1') } - fn get_target_voltage(&self) -> Result + fn get_nrst_voltage(&self) -> Result { - self.0.get_target_voltage() + self.0.get_nrst_voltage() } - fn get_srst_val(&self) -> Result + fn get_nrst_val(&self) -> Result { - self.0.get_srst_val() - } - - fn get_target_supply_power(&self) -> Result - { - self.0.get_target_supply_power() + self.0.get_nrst_val() } } diff --git a/src/serial/remote/protocol_v3.rs b/src/serial/remote/protocol_v3.rs index d141eab..02de3e6 100644 --- a/src/serial/remote/protocol_v3.rs +++ b/src/serial/remote/protocol_v3.rs @@ -113,19 +113,14 @@ impl BmdRemoteProtocol for RemoteV3 self.0.get_target_power_state() } - fn get_target_voltage(&self) -> Result + fn get_nrst_voltage(&self) -> Result { - self.0.get_target_voltage() + self.0.get_nrst_voltage() } - fn get_srst_val(&self) -> Result + fn get_nrst_val(&self) -> Result { - self.0.get_srst_val() - } - - fn get_target_supply_power(&self) -> Result - { - self.0.get_target_supply_power() + self.0.get_nrst_val() } } diff --git a/src/serial/remote/protocol_v4.rs b/src/serial/remote/protocol_v4.rs index 9906c95..c712c38 100644 --- a/src/serial/remote/protocol_v4.rs +++ b/src/serial/remote/protocol_v4.rs @@ -16,7 +16,7 @@ use crate::serial::remote::protocol_v3::RemoteV3; use crate::serial::remote::riscv_debug::RiscvDmi; use crate::serial::remote::{ Align, BmdAdiV5Protocol, BmdJtagProtocol, BmdRemoteProtocol, BmdRiscvProtocol, BmdSwdProtocol, JtagDev, - REMOTE_RESP_NOTSUP, REMOTE_RESP_OK, TargetAddr64, TargetArchitecture, TargetFamily, decode_response, + RemoteResponse, TargetAddr64, TargetArchitecture, TargetFamily, decode_response, }; pub struct RemoteV4 @@ -88,7 +88,7 @@ impl RemoteV4 let buffer = iface.buffer_read()?; drop(iface); // Check for communication failures - if buffer.is_empty() || buffer.as_bytes()[0] != REMOTE_RESP_OK { + if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::RESP_OK { return Err(eyre!( "Error talking with probe, expected OK response to supported accelerations query, got {:?}", buffer @@ -181,14 +181,16 @@ impl BmdRemoteProtocol for RemoteV4 self.interface().buffer_write(REMOTE_HL_ARCHS)?; let buffer = self.interface().buffer_read()?; // Check too see if that failed for some reason - if buffer.is_empty() || (buffer.as_bytes()[0] != REMOTE_RESP_OK && buffer.as_bytes()[0] != REMOTE_RESP_NOTSUP) { + if buffer.is_empty() || + (buffer.as_bytes()[0] != RemoteResponse::RESP_OK && buffer.as_bytes()[0] != RemoteResponse::RESP_NOTSUP) + { let message = if buffer.len() > 1 { &buffer[1..] } else { "unknown" }; Err(eyre!("Supported architectures request failed, error {}", message)) - } else if buffer.as_bytes()[0] == REMOTE_RESP_NOTSUP { + } else if buffer.as_bytes()[0] == RemoteResponse::RESP_NOTSUP { // If we get here, the probe talks v4 but doesn't know this command - meaning pre-v2.0.0 firmware // but post-v1.10.2. Ask the user to upgrade off development firmware onto the release or later. warn!("Please upgrade your firmware to allow checking supported target architectures to work properly"); @@ -206,14 +208,16 @@ impl BmdRemoteProtocol for RemoteV4 self.interface().buffer_write(REMOTE_HL_FAMILIES)?; let buffer = self.interface().buffer_read()?; // Check too see if that failed for some reason - if buffer.is_empty() || (buffer.as_bytes()[0] != REMOTE_RESP_OK && buffer.as_bytes()[0] != REMOTE_RESP_NOTSUP) { + if buffer.is_empty() || + (buffer.as_bytes()[0] != RemoteResponse::RESP_OK && buffer.as_bytes()[0] != RemoteResponse::RESP_NOTSUP) + { let message = if buffer.len() > 1 { &buffer[1..] } else { "unknown" }; Err(eyre!("Supported architectures request failed, error {}", message)) - } else if buffer.as_bytes()[0] == REMOTE_RESP_NOTSUP { + } else if buffer.as_bytes()[0] == RemoteResponse::RESP_NOTSUP { // If we get here, the probe talks v4 but doesn't know this command - meaning pre-v2.0.0 firmware // but post-v1.10.2. Ask the user to upgrade off development firmware onto the release or later. warn!("Please upgrade your firmware to allow checking supported target families to work properly"); @@ -230,19 +234,14 @@ impl BmdRemoteProtocol for RemoteV4 self.inner_protocol.get_target_power_state() } - fn get_target_voltage(&self) -> Result + fn get_nrst_voltage(&self) -> Result { - self.inner_protocol.get_target_voltage() + self.inner_protocol.get_nrst_voltage() } - fn get_srst_val(&self) -> Result + fn get_nrst_val(&self) -> Result { - self.inner_protocol.get_srst_val() - } - - fn get_target_supply_power(&self) -> Result - { - self.inner_protocol.get_target_supply_power() + self.inner_protocol.get_nrst_val() } } From 28efff939a78f4c5eec625b63b9c3e823ed94758 Mon Sep 17 00:00:00 2001 From: P-Storm Date: Wed, 30 Jul 2025 15:07:00 +0200 Subject: [PATCH 5/5] remote: removed the explicit lifetime --- src/serial/remote/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/serial/remote/mod.rs b/src/serial/remote/mod.rs index 326601e..bca8398 100644 --- a/src/serial/remote/mod.rs +++ b/src/serial/remote/mod.rs @@ -30,20 +30,20 @@ pub struct RemoteCommands; impl RemoteCommands { /// This command asks the probe if the reset pin is on - pub const GET_NRST: &'static str = "!Gz#"; + pub const GET_NRST: &str = "!Gz#"; /// This command asks the probe if power is being supplied to the target - pub const GET_TARGET_POWER_STATE: &'static str = "!Gp#"; + pub const GET_TARGET_POWER_STATE: &str = "!Gp#"; /// This command asks the probe what it's protocol version is - pub const HL_CHECK: &'static str = "!HC#"; + pub const HL_CHECK: &str = "!HC#"; /// This command asks the probe to initialise JTAG comms to any connected targets - pub const JTAG_INIT: &'static str = "!JS#"; - pub const NRST_TARGET_VOLTAGE: &'static str = "!GV#"; + pub const JTAG_INIT: &str = "!JS#"; + pub const NRST_TARGET_VOLTAGE: &str = "!GV#"; /// This command asks the probe to the reset pin state - pub const SET_NRST: &'static str = "!GZ#"; + pub const SET_NRST: &str = "!GZ#"; /// This command asks the probe to set the power state to the target - pub const SET_TARGET_POWER_STATE: &'static str = "!GP#"; + pub const SET_TARGET_POWER_STATE: &str = "!GP#"; /// This command asks to start remote protocol communications with the probe - pub const START: &'static str = "+#!GA#"; + pub const START: &str = "+#!GA#"; } pub struct RemoteResponse;