Fix connecting to S2 over USB (#813)

This commit is contained in:
Dániel Buga
2025-03-24 16:00:24 +01:00
committed by GitHub
parent dc81d8f5be
commit ee954b2c7b
2 changed files with 16 additions and 8 deletions

View File

@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `address` and `size` in `erase-region` have to be multiples of 4096 (#771)
- Fixed typos in error variant names (#782)
- Fix `read-flash` which didn't work with some lengths (#804)
- espflash can now flash an ESP32-S2 in download mode over USB (#813)
### Removed

View File

@@ -181,16 +181,23 @@ impl Connection {
// Reset the chip to bootloader (download mode)
reset_strategy.reset(&mut self.serial)?;
// S2 in USB download mode responds with 0 available bytes here
let available_bytes = self.serial.bytes_to_read()?;
buff = vec![0; available_bytes as usize];
let read_bytes = self.serial.read(&mut buff)? as u32;
if read_bytes != available_bytes {
return Err(Error::Connection(ConnectionError::ReadMissmatch(
available_bytes,
read_bytes,
)));
}
buff = vec![0; available_bytes as usize];
let read_bytes = if available_bytes > 0 {
let read_bytes = self.serial.read(&mut buff)? as u32;
if read_bytes != available_bytes {
return Err(Error::Connection(ConnectionError::ReadMissmatch(
available_bytes,
read_bytes,
)));
}
read_bytes
} else {
0
};
let read_slice = String::from_utf8_lossy(&buff[..read_bytes as usize]).into_owned();