Skip to content

Commit 544f700

Browse files
MabezDevjessebraham
authored andcommitted
Disable RTC WDT on connect for USB-SERIAL-JTAG
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.
1 parent 841db26 commit 544f700

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

espflash/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
};
1717

1818
const DEFAULT_CONNECT_ATTEMPTS: usize = 7;
19-
const USB_SERIAL_JTAG_PID: u16 = 0x1001;
19+
pub const USB_SERIAL_JTAG_PID: u16 = 0x1001;
2020

2121
#[derive(Debug, Copy, Clone, BinRead)]
2222
pub struct CommandResponse {

espflash/src/flash_target/esp32.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::command::{Command, CommandType};
2-
use crate::connection::Connection;
2+
use crate::connection::{Connection, USB_SERIAL_JTAG_PID};
33
use crate::elf::{FirmwareImage, RomSegment};
44
use crate::error::Error;
55
use crate::flash_target::FlashTarget;
@@ -31,6 +31,49 @@ impl FlashTarget for Esp32Target {
3131
spi_params: self.spi_attach_params,
3232
})
3333
})?;
34+
35+
// TODO remove this when we use the stub, the stub should be taking care of this.
36+
// TODO do we also need to disable rtc super wdt?
37+
if connection.get_usb_pid()? == USB_SERIAL_JTAG_PID {
38+
match self.chip {
39+
Chip::Esp32c3 => {
40+
connection.command(Command::WriteReg {
41+
address: 0x600080a8,
42+
value: 0x50D83AA1u32,
43+
mask: None,
44+
})?; // WP disable
45+
connection.command(Command::WriteReg {
46+
address: 0x60008090,
47+
value: 0x0,
48+
mask: None,
49+
})?; // turn off RTC WDG
50+
connection.command(Command::WriteReg {
51+
address: 0x600080a8,
52+
value: 0x0,
53+
mask: None,
54+
})?; // WP enable
55+
}
56+
Chip::Esp32s3 => {
57+
connection.command(Command::WriteReg {
58+
address: 0x00B0,
59+
value: 0x50D83AA1u32,
60+
mask: None,
61+
})?; // WP disable
62+
connection.command(Command::WriteReg {
63+
address: 0x0098,
64+
value: 0x0,
65+
mask: None,
66+
})?; // turn off RTC WDG
67+
connection.command(Command::WriteReg {
68+
address: 0x00B0,
69+
value: 0x0,
70+
mask: None,
71+
})?; // WP enable
72+
}
73+
_ => {}
74+
}
75+
}
76+
3477
Ok(())
3578
}
3679

0 commit comments

Comments
 (0)