Skip to content

Commit 3ce11c3

Browse files
committed
fix: Esp32 tests
1 parent 17c9f43 commit 3ce11c3

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

espflash/src/connection/mod.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -750,35 +750,29 @@ impl Connection {
750750
&mut self,
751751
use_stub: bool,
752752
) -> Result<crate::target::Chip, crate::error::Error> {
753-
// First try to detect chip using security_info when possible
754-
if let Ok(security_info) = self.security_info(use_stub) {
755-
if let Some(chip_id) = security_info.chip_id {
756-
debug!("Detected chip using security info chip_id: {chip_id}");
757-
// Convert u32 chip_id to u16 for compatibility with Chip::try_from
758-
match Chip::try_from(chip_id as u16) {
759-
Ok(chip) => return Ok(chip),
760-
Err(_) => {
761-
debug!(
762-
"Unknown chip_id from security_info: {chip_id}, falling back to magic register"
763-
);
764-
}
765-
}
753+
match self.security_info(use_stub) {
754+
Ok(info) if info.chip_id.is_some() => {
755+
let chip_id = info.chip_id.unwrap() as u16;
756+
let chip = Chip::try_from(chip_id)?;
757+
758+
Ok(chip)
759+
}
760+
_ => {
761+
// Fall back to reading the magic value from the chip
762+
let magic = if use_stub {
763+
self.with_timeout(CommandType::ReadReg.timeout(), |connection| {
764+
connection.command(Command::ReadReg {
765+
address: CHIP_DETECT_MAGIC_REG_ADDR,
766+
})
767+
})?
768+
.try_into()?
769+
} else {
770+
self.read_reg(CHIP_DETECT_MAGIC_REG_ADDR)?
771+
};
772+
debug!("Read chip magic value: 0x{magic:08x}");
773+
Chip::from_magic(magic)
766774
}
767775
}
768-
769-
// Fall back to reading the magic value from the chip
770-
let magic = if use_stub {
771-
self.with_timeout(CommandType::ReadReg.timeout(), |connection| {
772-
connection.command(Command::ReadReg {
773-
address: CHIP_DETECT_MAGIC_REG_ADDR,
774-
})
775-
})?
776-
.try_into()?
777-
} else {
778-
self.read_reg(CHIP_DETECT_MAGIC_REG_ADDR)?
779-
};
780-
debug!("Read chip magic value: 0x{magic:08x}");
781-
Chip::from_magic(magic)
782776
}
783777
}
784778

0 commit comments

Comments
 (0)