Skip to content
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

Fix sync behavior #217

Merged
merged 2 commits into from
Aug 16, 2022
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
20 changes: 8 additions & 12 deletions espflash/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ impl Connection {

fn sync(&mut self) -> Result<(), Error> {
self.with_timeout(CommandType::Sync.timeout(), |connection| {
connection.write_command(Command::Sync)?;
connection.command(Command::Sync)?;
connection.flush()?;
sleep(Duration::from_millis(10));
for _ in 0..100 {
for _ in 0..7 {
match connection.read_response()? {
Some(response) if response.return_op == CommandType::Sync as u8 => {
if response.status == 1 {
Expand All @@ -100,24 +100,20 @@ impl Connection {
CommandType::Sync,
RomErrorKind::from(response.error),
)));
} else {
break;
}
}
_ => continue,
_ => {
return Err(Error::RomError(RomError::new(
CommandType::Sync,
RomErrorKind::InvalidMessage,
)))
}
}
}

Ok(())
})?;

for _ in 0..700 {
match self.read_response()? {
Some(_) => break,
_ => continue,
}
}

Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions espflash/src/partition_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const MD5_PART_MAGIC_BYTES: &[u8] = &[
];
const END_MARKER: [u8; 32] = [0xFF; 32];

#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Display for Type {
}
}

#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
pub enum AppType {
Expand Down Expand Up @@ -104,7 +104,7 @@ pub enum AppType {
Test = 0x20,
}

#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
#[serde(rename_all = "lowercase")]
Expand All @@ -127,7 +127,7 @@ impl DataType {
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Copy, Clone, BinRead)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Copy, Clone, BinRead)]
#[serde(untagged)]
pub enum SubType {
App(AppType),
Expand Down Expand Up @@ -162,7 +162,7 @@ impl SubType {
}
}

#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
#[serde(rename_all = "lowercase")]
Expand Down