Skip to content

Commit 1e18c35

Browse files
committed
fix: Esp32 tests
1 parent 284baf6 commit 1e18c35

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

espflash/src/connection/mod.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -757,35 +757,20 @@ impl Connection {
757757
&mut self,
758758
use_stub: bool,
759759
) -> Result<crate::target::Chip, crate::error::Error> {
760-
// First try to detect chip using security_info when possible
761-
if let Ok(security_info) = self.security_info(use_stub) {
762-
if let Some(chip_id) = security_info.chip_id {
763-
debug!("Detected chip using security info chip_id: {chip_id}");
764-
// Convert u32 chip_id to u16 for compatibility with Chip::try_from
765-
match Chip::try_from(chip_id as u16) {
766-
Ok(chip) => return Ok(chip),
767-
Err(_) => {
768-
debug!(
769-
"Unknown chip_id from security_info: {chip_id}, falling back to magic register"
770-
);
771-
}
772-
}
760+
match self.security_info(use_stub) {
761+
Ok(info) if info.chip_id.is_some() => {
762+
let chip_id = info.chip_id.unwrap() as u16;
763+
let chip = Chip::try_from(chip_id)?;
764+
765+
Ok(chip)
773766
}
774-
}
767+
_ => {
768+
let magic = self.read_reg(CHIP_DETECT_MAGIC_REG_ADDR)?;
769+
let chip = Chip::from_magic(magic)?;
775770

776-
// Fall back to reading the magic value from the chip
777-
let magic = if use_stub {
778-
self.with_timeout(CommandType::ReadReg.timeout(), |connection| {
779-
connection.command(Command::ReadReg {
780-
address: CHIP_DETECT_MAGIC_REG_ADDR,
781-
})
782-
})?
783-
.try_into()?
784-
} else {
785-
self.read_reg(CHIP_DETECT_MAGIC_REG_ADDR)?
786-
};
787-
debug!("Read chip magic value: 0x{magic:08x}");
788-
Chip::from_magic(magic)
771+
Ok(chip)
772+
}
773+
}
789774
}
790775
}
791776

0 commit comments

Comments
 (0)