Skip to content

Commit

Permalink
Disable RTC WDT on connect for USB-SERIAL-JTAG
Browse files Browse the repository at this point in the history
When the chip is reset via the USB-SERIAL-JTAG not everything is fully
reset, the RTC domain stays active. Therefore, if the RTC watchdog is
enabled before being put into download mode it will trigger when
flashing, hence resetting the board and interrupting flashing.
  • Loading branch information
MabezDev committed Apr 27, 2022
1 parent 3a4c02b commit 1c8cad0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion espflash/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
};

const DEFAULT_CONNECT_ATTEMPTS: usize = 7;
const USB_SERIAL_JTAG_PID: u16 = 0x1001;
pub const USB_SERIAL_JTAG_PID: u16 = 0x1001;

#[derive(Debug, Copy, Clone, BinRead)]
pub struct CommandResponse {
Expand Down
45 changes: 44 additions & 1 deletion espflash/src/flash_target/esp32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::command::{Command, CommandType};
use crate::connection::Connection;
use crate::connection::{Connection, USB_SERIAL_JTAG_PID};
use crate::elf::{FirmwareImage, RomSegment};
use crate::error::Error;
use crate::flash_target::FlashTarget;
Expand Down Expand Up @@ -31,6 +31,49 @@ impl FlashTarget for Esp32Target {
spi_params: self.spi_attach_params,
})
})?;

// TODO remove this when we use the stub, the stub should be taking care of this.
// TODO do we also need to disable rtc super wdt?
if connection.get_usb_pid()? == USB_SERIAL_JTAG_PID {
match self.chip {
Chip::Esp32c3 => {
connection.command(Command::WriteReg {
address: 0x600080a8,
value: 0x50D83AA1u32,
mask: None,
})?; // WP disable
connection.command(Command::WriteReg {
address: 0x60008090,
value: 0x0,
mask: None,
})?; // turn off RTC WDG
connection.command(Command::WriteReg {
address: 0x600080a8,
value: 0x0,
mask: None,
})?; // WP enable
}
Chip::Esp32s3 => {
connection.command(Command::WriteReg {
address: 0x00B0,
value: 0x50D83AA1u32,
mask: None,
})?; // WP disable
connection.command(Command::WriteReg {
address: 0x0098,
value: 0x0,
mask: None,
})?; // turn off RTC WDG
connection.command(Command::WriteReg {
address: 0x00B0,
value: 0x0,
mask: None,
})?; // WP enable
}
_ => {}
}
}

Ok(())
}

Expand Down

0 comments on commit 1c8cad0

Please sign in to comment.