Skip to content

Commit 57572d9

Browse files
ryankurtemertzt89
andcommitted
support baud rate switching with flash stubs
Co-authored-by: Timothy Mertz <[email protected]>
1 parent 26e7c00 commit 57572d9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

espflash/src/command.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ pub enum Command<'a> {
113113
spi_params: SpiAttachParams,
114114
},
115115
ChangeBaud {
116-
speed: u32,
116+
/// New baud rate
117+
new_baud: u32,
118+
/// Prior baud rate ('0' for ROM flasher)
119+
prior_baud: u32,
117120
},
118121
FlashDeflateBegin {
119122
size: u32,
@@ -267,14 +270,14 @@ impl<'a> Command<'a> {
267270
Command::SpiAttach { spi_params } => {
268271
write_basic(writer, &spi_params.encode(), 0)?;
269272
}
270-
Command::ChangeBaud { speed } => {
273+
Command::ChangeBaud { new_baud, prior_baud } => {
271274
// length
272275
writer.write_all(&(8u16.to_le_bytes()))?;
273276
// checksum
274277
writer.write_all(&(0u32.to_le_bytes()))?;
275278
// data
276-
writer.write_all(&speed.to_le_bytes())?;
277-
writer.write_all(&0u32.to_le_bytes())?;
279+
writer.write_all(&new_baud.to_le_bytes())?;
280+
writer.write_all(&prior_baud.to_le_bytes())?;
278281
}
279282
Command::FlashDeflateBegin {
280283
size,

espflash/src/flasher.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,16 @@ struct EntryParams {
183183
}
184184

185185
pub struct Flasher {
186+
/// Connection for flash operations
186187
connection: Connection,
188+
/// Chip ID
187189
chip: Chip,
190+
/// Flash size, loaded from SPI flash
188191
flash_size: FlashSize,
192+
/// Configuration for SPI attached flash (0 to use fused values)
189193
spi_params: SpiAttachParams,
194+
/// Indicate RAM stub loader is in use
195+
use_stub: bool,
190196
}
191197

192198
impl Flasher {
@@ -211,6 +217,7 @@ impl Flasher {
211217
chip,
212218
flash_size: FlashSize::Flash4Mb,
213219
spi_params: SpiAttachParams::default(),
220+
use_stub,
214221
};
215222

216223
// Load flash stub if enabled
@@ -590,9 +597,16 @@ impl Flasher {
590597
}
591598

592599
pub fn change_baud(&mut self, speed: u32) -> Result<(), Error> {
600+
debug!("Change baud to: {}", speed);
601+
602+
let prior_baud = match self.use_stub {
603+
true => self.connection.get_baud()?,
604+
false => 0,
605+
};
606+
593607
self.connection
594608
.with_timeout(CommandType::ChangeBaud.timeout(), |connection| {
595-
connection.command(Command::ChangeBaud { speed })
609+
connection.command(Command::ChangeBaud { new_baud: speed, prior_baud })
596610
})?;
597611
self.connection.set_baud(speed)?;
598612
std::thread::sleep(Duration::from_secs_f32(0.05));

0 commit comments

Comments
 (0)