Skip to content

Fix connecting to S2 over USB #813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 15 additions & 8 deletions espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading