Skip to content

Commit

Permalink
chore: refine special erase check
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Oct 3, 2023
1 parent 31af071 commit 68b0436
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ impl RiscvChip {
)
}

/// Erase code flash by RST pin or power-off
pub fn support_special_erase(&self) -> bool {
self.support_query_info()
}

pub fn reset_command(&self) -> crate::commands::Reset {
match self {
RiscvChip::CH57X | RiscvChip::CH58X | RiscvChip::CH59X => {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn main() -> Result<()> {
log::info!("{dmstatus:#?}");
}
Erase { method } => {
log::info!("Erase Flash using {:?}", method);
log::info!("Erase Flash using {:?} method", method);
match method {
EraseMode::Default => {
probe.erase_flash()?;
Expand Down
11 changes: 9 additions & 2 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,19 @@ impl WchLink {

/// Clear All Code Flash - By Power off
pub fn erase_flash_by_power_off(&mut self) -> Result<()> {
if self.probe.as_ref().unwrap().variant.support_power_funcs() {
if self.probe.as_ref().unwrap().variant.support_power_funcs()
&& self
.chip
.as_ref()
.unwrap()
.chip_family
.support_special_erase()
{
self.send_command(control::EraseCodeFlash::ByPowerOff)?;
Ok(())
} else {
Err(Error::Custom(format!(
"Probe doesn't support power off erase",
"Probe or Chip doesn't support power off erase",
)))
}
}
Expand Down

0 comments on commit 68b0436

Please sign in to comment.