Skip to content

Commit 1121536

Browse files
committed
efuse: Implement write support
1 parent 6d2128a commit 1121536

File tree

5 files changed

+767
-1
lines changed

5 files changed

+767
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

espflash/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ log = "0.4"
5050
md-5 = "0.10"
5151
miette = "7.6"
5252
object = "0.37"
53+
reed-solomon = "0.2.1"
5354
regex = { version = "1.11", optional = true }
5455
serde = { version = "1.0", features = ["derive"] }
5556
serialport = { version = "4.7", default-features = false, optional = true }

espflash/src/connection/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,16 @@ impl Connection {
683683
Ok(())
684684
}
685685

686+
/// Updates a register by applying the new value to the masked out portion
687+
/// of the old value.
688+
pub(crate) fn update_reg(&mut self, addr: u32, mask: u32, new_value: u32) -> Result<(), Error> {
689+
let masked_new_value = new_value.checked_shl(mask.trailing_zeros()).unwrap_or(0) & mask;
690+
691+
let masked_old_value = self.read_reg(addr)? & !mask;
692+
693+
self.write_reg(addr, masked_old_value | masked_new_value, None)
694+
}
695+
686696
/// Reads a register command with a timeout.
687697
pub(crate) fn read(&mut self, len: usize) -> Result<Option<Vec<u8>>, Error> {
688698
let mut tmp = Vec::with_capacity(1024);

espflash/src/error.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,22 @@ pub enum Error {
367367
/// Specified eFuse block does not exist
368368
#[error("specified eFuse block does not exist: {0}")]
369369
InvalidEfuseBlock(u32),
370+
371+
/// Unsupported crystall frequency
372+
#[error("Unsupported crystal frequency: {0}")]
373+
UnsupportedXtalFrequency(String),
374+
375+
/// Failed to write eFuse
376+
#[error("Failed to write eFuse: {0}")]
377+
WritingEfuseFailed(String),
378+
379+
/// Timed out while waiting for eFuse controller to return to idle
380+
#[error("Timed out while waiting for eFuse controller to return to idle")]
381+
TimedOutWaitingForEfuseController,
382+
383+
/// Tried to use an unsupported eFuse coding scheme
384+
#[error("Tried to use an unsupported eFuse coding scheme: {0}")]
385+
UnsupportedEfuseCodingScheme(String),
370386
}
371387

372388
#[cfg(feature = "serialport")]

0 commit comments

Comments
 (0)