-
-
Notifications
You must be signed in to change notification settings - Fork 10
Enhance bmputil-cli target power
#57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f1246fc
65be5f7
9fcb31b
40f82b4
28efff9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,25 +25,49 @@ mod protocol_v3; | |
| mod protocol_v4; | ||
| pub mod riscv_debug; | ||
|
|
||
| /// 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; | ||
| pub struct RemoteCommands; | ||
|
|
||
| /// 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'&'; | ||
| impl RemoteCommands | ||
| { | ||
| /// This command asks the probe if the reset pin is on | ||
| 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: &str = "!Gp#"; | ||
| /// This command asks the probe what it's protocol version is | ||
| pub const HL_CHECK: &str = "!HC#"; | ||
| /// This command asks the probe to initialise JTAG comms to any connected targets | ||
| pub const JTAG_INIT: &str = "!JS#"; | ||
| pub const NRST_TARGET_VOLTAGE: &str = "!GV#"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure what happened here, but this one isn't documented now and the constant is misnamed for what it does - this retrieves the target voltage. |
||
| /// This command asks the probe to the reset pin state | ||
| 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: &str = "!GP#"; | ||
| /// This command asks to start remote protocol communications with the probe | ||
| pub const START: &str = "+#!GA#"; | ||
| } | ||
|
|
||
| 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; | ||
|
Comment on lines
+55
to
+57
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NB: this constant is not specific to the response - it sets the request max length too. |
||
| /// 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'!'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is part of the request not response - same for EOM above. It's the RESP marker that indicates the start of a response. |
||
| } | ||
|
|
||
| pub type TargetAddr32 = u32; | ||
| pub type TargetAddr64 = u64; | ||
|
|
@@ -112,6 +136,8 @@ pub trait BmdRemoteProtocol | |
| fn supported_architectures(&self) -> Result<Option<TargetArchitecture>>; | ||
| fn supported_families(&self) -> Result<Option<TargetFamily>>; | ||
| fn get_target_power_state(&self) -> Result<bool>; | ||
| fn get_nrst_voltage(&self) -> Result<f32>; | ||
| fn get_nrst_val(&self) -> Result<bool>; | ||
| } | ||
|
|
||
| /// Types implementing this trait provide raw SWD access to targets over the BMD remote protocol | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // SPDX-License-Identifier: MIT OR Apache-2.0 | ||
| // SPDX-FileCopyrightText: 2025 1BitSquared <[email protected]> | ||
| // SPDX-FileContributor: Written by Rachel Mant <[email protected]> | ||
| // SPDX-FileContributor: Modified by P-Storm <[email protected]> | ||
|
|
||
| use std::sync::{Arc, Mutex, MutexGuard}; | ||
|
|
||
|
|
@@ -11,7 +12,7 @@ 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, | ||
| RemoteCommands, RemoteResponse, TargetAddr64, TargetArchitecture, TargetFamily, | ||
| }; | ||
|
|
||
| pub struct RemoteV0 | ||
|
|
@@ -83,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 { | ||
|
|
@@ -102,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 { | ||
|
|
@@ -169,6 +170,44 @@ impl BmdRemoteProtocol for RemoteV0 | |
| { | ||
| Err(eyre!("Not supported")) | ||
| } | ||
|
|
||
| fn get_nrst_voltage(&self) -> Result<f32> | ||
| { | ||
| self.interface().buffer_write(RemoteCommands::NRST_TARGET_VOLTAGE)?; | ||
| let buffer = self.interface().buffer_read()?; | ||
|
|
||
| if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::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::<f32>() | ||
| .map_err(|e| eyre!("Can't parse target voltage value to a float, input {}, reason: {}", value, e)) | ||
| } | ||
|
|
||
| fn get_nrst_val(&self) -> Result<bool> | ||
| { | ||
| self.interface().buffer_write(RemoteCommands::GET_NRST)?; | ||
| let buffer = self.interface().buffer_read()?; | ||
|
|
||
| if buffer.is_empty() || buffer.as_bytes()[0] != RemoteResponse::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') | ||
| } | ||
| } | ||
|
|
||
| impl From<Arc<Mutex<BmdRspInterface>>> for RemoteV0Plus | ||
|
|
@@ -253,6 +292,16 @@ impl BmdRemoteProtocol for RemoteV0Plus | |
| { | ||
| self.0.get_target_power_state() | ||
| } | ||
|
|
||
| fn get_nrst_voltage(&self) -> Result<f32> | ||
| { | ||
| self.0.get_nrst_voltage() | ||
| } | ||
|
|
||
| fn get_nrst_val(&self) -> Result<bool> | ||
| { | ||
| self.0.get_nrst_val() | ||
| } | ||
| } | ||
|
|
||
| impl From<Arc<Mutex<BmdRspInterface>>> for RemoteV0JTAG | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // SPDX-License-Identifier: MIT OR Apache-2.0 | ||
| // SPDX-FileCopyrightText: 2025 1BitSquared <[email protected]> | ||
| // SPDX-FileContributor: Written by Rachel Mant <[email protected]> | ||
| // SPDX-FileContributor: Modified by P-Storm <[email protected]> | ||
|
|
||
| use std::sync::{Arc, Mutex, MutexGuard}; | ||
|
|
||
|
|
@@ -115,6 +116,16 @@ impl BmdRemoteProtocol for RemoteV1 | |
| { | ||
| self.0.get_target_power_state() | ||
| } | ||
|
|
||
| fn get_nrst_voltage(&self) -> Result<f32> | ||
| { | ||
| self.0.get_nrst_voltage() | ||
| } | ||
|
|
||
| fn get_nrst_val(&self) -> Result<bool> | ||
| { | ||
| self.0.get_nrst_val() | ||
| } | ||
| } | ||
|
|
||
| impl From<Arc<Mutex<BmdRspInterface>>> for RemoteV1ADIv5 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.