Browse Source

chore: refine special erase check

pull/32/head
Andelf 1 year ago
parent
commit
2af8651a41
  1. 5
      src/lib.rs
  2. 2
      src/main.rs
  3. 11
      src/operations.rs

5
src/lib.rs

@ -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 => {

2
src/main.rs

@ -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()?;

11
src/operations.rs

@ -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",
)))
}
}

Loading…
Cancel
Save