Skip to content

Commit 47aacaf

Browse files
committed
Add P4
1 parent 6bbca41 commit 47aacaf

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

espflash/src/connection/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use self::{
3636
};
3737
use crate::{
3838
error::{ConnectionError, Error, ResultExt, RomError, RomErrorKind},
39-
targets::{esp32s2, esp32s3, Chip},
39+
targets::{esp32p4, esp32s2, esp32s3, Chip},
4040
};
4141

4242
pub(crate) mod command;
@@ -290,6 +290,13 @@ impl Connection {
290290
wdt_reset(chip, self)?;
291291
}
292292
}
293+
Chip::Esp32p4 => {
294+
let esp32p4 = esp32p4::Esp32p4;
295+
// Check if the connection is USB OTG
296+
if esp32p4.connection_is_usb_otg(self)? {
297+
wdt_reset(chip, self)?;
298+
}
299+
}
293300
Chip::Esp32s2 => {
294301
let esp32s2 = esp32s2::Esp32s2;
295302
// Check if the connection is USB OTG

espflash/src/connection/reset.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,21 @@ impl RtcWdtReset for crate::targets::esp32c3::Esp32c3 {
222222
}
223223
}
224224

225+
impl RtcWdtReset for crate::targets::esp32p4::Esp32p4 {
226+
fn wdt_wprotect(&self) -> u32 {
227+
0x5011_6000 + 0x0018
228+
}
229+
fn wdt_wkey(&self) -> u32 {
230+
0x50D8_3AA1
231+
}
232+
fn wdt_config0(&self) -> u32 {
233+
0x5011_6000 // no offset here
234+
}
235+
fn wdt_config1(&self) -> u32 {
236+
0x5011_6000 + 0x0004
237+
}
238+
}
239+
225240
impl RtcWdtReset for crate::targets::esp32s2::Esp32s2 {
226241
fn wdt_wprotect(&self) -> u32 {
227242
0x3F40_8000 + 0x00AC

espflash/src/targets/esp32p4.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ const PARAMS: Esp32Params = Esp32Params::new(
3030
pub struct Esp32p4;
3131

3232
impl Esp32p4 {
33+
/// Check if the magic value contains the specified value
3334
pub fn has_magic_value(value: u32) -> bool {
3435
CHIP_DETECT_MAGIC_VALUES.contains(&value)
3536
}
37+
38+
#[cfg(feature = "serialport")]
39+
/// Check if the connection is USB OTG
40+
pub(crate) fn connection_is_usb_otg(&self, connection: &mut Connection) -> Result<bool, Error> {
41+
const UARTDEV_BUF_NO: u32 = 0x4FF3_FEC8; // Address which indicates OTG in use
42+
const UARTDEV_BUF_NO_USB_OTG: u32 = 5; // Value of UARTDEV_BUF_NO when OTG is in use
43+
44+
Ok(connection.read_reg(UARTDEV_BUF_NO)? == UARTDEV_BUF_NO_USB_OTG)
45+
}
3646
}
3747

3848
impl ReadEFuse for Esp32p4 {

espflash/src/targets/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod esp32c2;
4343
pub(crate) mod esp32c3;
4444
mod esp32c6;
4545
mod esp32h2;
46-
mod esp32p4;
46+
pub(crate) mod esp32p4;
4747
pub(crate) mod esp32s2;
4848
pub(crate) mod esp32s3;
4949

0 commit comments

Comments
 (0)