Skip to content

Commit

Permalink
Disable watchdog timer before build. (#363)
Browse files Browse the repository at this point in the history
* Ignore CLion project.

* Disable watchdog timer before build.

* Fix formatting.

* Re-enable the code to disable the watchdog, even if the flash stub is in use.
  • Loading branch information
jnross authored Mar 24, 2023
1 parent 62b882e commit e120913
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ target/
.vscode/
.DS_Store
*.swp
.idea/
1 change: 1 addition & 0 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
let chip = flasher.chip();
let target = chip.into_target();
let target_xtal_freq = target.crystal_freq(flasher.connection())?;
flasher.disable_watchdog()?;

let build_ctx =
build(&args.build_args, &cargo_config, chip).wrap_err("Failed to build project")?;
Expand Down
6 changes: 6 additions & 0 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ impl Flasher {
Ok(flasher)
}

pub fn disable_watchdog(&mut self) -> Result<(), Error> {
let mut target = self.chip.flash_target(self.spi_params, self.use_stub);
target.begin(&mut self.connection).flashing()?;
Ok(())
}

/// Load flash stub
fn load_stub(&mut self) -> Result<(), Error> {
debug!("Loading flash stub for chip: {:?}", self.chip);
Expand Down
4 changes: 3 additions & 1 deletion espflash/src/targets/flash_target/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ impl FlashTarget for Esp32Target {

// The stub usually disables these watchdog timers, however if we're not using the stub
// we need to disable them before flashing begins
if !self.use_stub && connection.get_usb_pid()? == USB_SERIAL_JTAG_PID {
// TODO: the stub doesn't appear to disable the watchdog on ESP32-S3, so we explicitly
// disable the watchdog here.
if connection.get_usb_pid()? == USB_SERIAL_JTAG_PID {
match self.chip {
Chip::Esp32c3 => {
connection.command(Command::WriteReg {
Expand Down

0 comments on commit e120913

Please sign in to comment.