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

enable support for loader stubs (via --use-stub arg) #216

Merged
merged 9 commits into from
Aug 17, 2022
11 changes: 7 additions & 4 deletions espflash/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ pub enum Command<'a> {
spi_params: SpiAttachParams,
},
ChangeBaud {
speed: u32,
/// New baud rate
new_baud: u32,
/// Prior baud rate ('0' for ROM flasher)
prior_baud: u32,
},
FlashDeflateBegin {
size: u32,
Expand Down Expand Up @@ -267,14 +270,14 @@ impl<'a> Command<'a> {
Command::SpiAttach { spi_params } => {
write_basic(writer, &spi_params.encode(), 0)?;
}
Command::ChangeBaud { speed } => {
Command::ChangeBaud { new_baud, prior_baud } => {
// length
writer.write_all(&(8u16.to_le_bytes()))?;
// checksum
writer.write_all(&(0u32.to_le_bytes()))?;
// data
writer.write_all(&speed.to_le_bytes())?;
writer.write_all(&0u32.to_le_bytes())?;
writer.write_all(&new_baud.to_le_bytes())?;
writer.write_all(&prior_baud.to_le_bytes())?;
ryankurte marked this conversation as resolved.
Show resolved Hide resolved
}
Command::FlashDeflateBegin {
size,
Expand Down
16 changes: 15 additions & 1 deletion espflash/src/flasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,16 @@ struct EntryParams {
}

pub struct Flasher {
/// Connection for flash operations
connection: Connection,
/// Chip ID
chip: Chip,
/// Flash size, loaded from SPI flash
flash_size: FlashSize,
/// Configuration for SPI attached flash (0 to use fused values)
spi_params: SpiAttachParams,
/// Indicate RAM stub loader is in use
use_stub: bool,
}

impl Flasher {
Expand All @@ -211,6 +217,7 @@ impl Flasher {
chip,
flash_size: FlashSize::Flash4Mb,
spi_params: SpiAttachParams::default(),
use_stub,
};

// Load flash stub if enabled
Expand Down Expand Up @@ -590,9 +597,16 @@ impl Flasher {
}

pub fn change_baud(&mut self, speed: u32) -> Result<(), Error> {
debug!("Change baud to: {}", speed);

let prior_baud = match self.use_stub {
true => self.connection.get_baud()?,
false => 0,
};

self.connection
.with_timeout(CommandType::ChangeBaud.timeout(), |connection| {
connection.command(Command::ChangeBaud { speed })
connection.command(Command::ChangeBaud { new_baud: speed, prior_baud })
})?;
self.connection.set_baud(speed)?;
std::thread::sleep(Duration::from_secs_f32(0.05));
Expand Down