Skip to content

Commit

Permalink
Add P4
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajSadel committed Feb 25, 2025
1 parent 6bbca41 commit 47aacaf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
9 changes: 8 additions & 1 deletion espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use self::{
};
use crate::{
error::{ConnectionError, Error, ResultExt, RomError, RomErrorKind},
targets::{esp32s2, esp32s3, Chip},
targets::{esp32p4, esp32s2, esp32s3, Chip},
};

pub(crate) mod command;
Expand Down Expand Up @@ -290,6 +290,13 @@ impl Connection {
wdt_reset(chip, self)?;
}
}
Chip::Esp32p4 => {
let esp32p4 = esp32p4::Esp32p4;
// Check if the connection is USB OTG
if esp32p4.connection_is_usb_otg(self)? {
wdt_reset(chip, self)?;
}
}
Chip::Esp32s2 => {
let esp32s2 = esp32s2::Esp32s2;
// Check if the connection is USB OTG
Expand Down
15 changes: 15 additions & 0 deletions espflash/src/connection/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ impl RtcWdtReset for crate::targets::esp32c3::Esp32c3 {
}
}

impl RtcWdtReset for crate::targets::esp32p4::Esp32p4 {
fn wdt_wprotect(&self) -> u32 {
0x5011_6000 + 0x0018
}
fn wdt_wkey(&self) -> u32 {
0x50D8_3AA1
}
fn wdt_config0(&self) -> u32 {
0x5011_6000 // no offset here
}
fn wdt_config1(&self) -> u32 {
0x5011_6000 + 0x0004
}
}

impl RtcWdtReset for crate::targets::esp32s2::Esp32s2 {
fn wdt_wprotect(&self) -> u32 {
0x3F40_8000 + 0x00AC
Expand Down
10 changes: 10 additions & 0 deletions espflash/src/targets/esp32p4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ const PARAMS: Esp32Params = Esp32Params::new(
pub struct Esp32p4;

impl Esp32p4 {
/// Check if the magic value contains the specified value
pub fn has_magic_value(value: u32) -> bool {
CHIP_DETECT_MAGIC_VALUES.contains(&value)
}

#[cfg(feature = "serialport")]
/// Check if the connection is USB OTG
pub(crate) fn connection_is_usb_otg(&self, connection: &mut Connection) -> Result<bool, Error> {
const UARTDEV_BUF_NO: u32 = 0x4FF3_FEC8; // Address which indicates OTG in use
const UARTDEV_BUF_NO_USB_OTG: u32 = 5; // Value of UARTDEV_BUF_NO when OTG is in use

Ok(connection.read_reg(UARTDEV_BUF_NO)? == UARTDEV_BUF_NO_USB_OTG)
}
}

impl ReadEFuse for Esp32p4 {
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod esp32c2;
pub(crate) mod esp32c3;
mod esp32c6;
mod esp32h2;
mod esp32p4;
pub(crate) mod esp32p4;
pub(crate) mod esp32s2;
pub(crate) mod esp32s3;

Expand Down

0 comments on commit 47aacaf

Please sign in to comment.