From 1f628e359c08666407fd2e30e4aa193a51ddbc48 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Fri, 22 Dec 2023 14:28:21 +0000 Subject: [PATCH] Add support for the ESP32-P4 (#61) * Add support for the ESP32-P4 * Update the CI workflow to check the ESP32-P4 --- .github/workflows/ci.yml | 1 + Cargo.toml | 3 ++- build.rs | 2 ++ src/lib.rs | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45c0bfd..4d66b4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,7 @@ jobs: { chip: "esp32c3", target: "riscv32imc-unknown-none-elf" }, { chip: "esp32c6", target: "riscv32imac-unknown-none-elf" }, { chip: "esp32h2", target: "riscv32imac-unknown-none-elf" }, + { chip: "esp32p4", target: "riscv32imafc-unknown-none-elf" }, ] steps: diff --git a/Cargo.toml b/Cargo.toml index 27ad790..1d68317 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ esp32c2 = [] esp32c3 = [] esp32c6 = [] esp32h2 = [] +esp32p4 = [] esp32s2 = [] esp32s3 = [] esp8266 = [] @@ -38,7 +39,7 @@ esp8266 = [] # You must enable exactly 1 of the below features to enable to intended # communication method (note that "uart" is enabled by default): uart = [] -jtag-serial = ["portable-atomic"] # C3, C6, H2, and S3 only! +jtag-serial = ["portable-atomic"] # C3, C6, H2, P4, and S3 only! no-op = [] # Enables a `defmt` backend usable with espflash. We force rzcobs encoding to simplify implementation diff --git a/build.rs b/build.rs index e970462..0f9e3bc 100644 --- a/build.rs +++ b/build.rs @@ -6,6 +6,7 @@ fn main() { cfg!(feature = "esp32c3"), cfg!(feature = "esp32c6"), cfg!(feature = "esp32h2"), + cfg!(feature = "esp32p4"), cfg!(feature = "esp32s2"), cfg!(feature = "esp32s3"), cfg!(feature = "esp8266"), @@ -33,6 +34,7 @@ fn main() { && !(cfg!(feature = "esp32c3") || cfg!(feature = "esp32c6") || cfg!(feature = "esp32h2") + || cfg!(feature = "esp32p4") || cfg!(feature = "esp32s3")) { panic!( diff --git a/src/lib.rs b/src/lib.rs index 7eb2ff4..244022d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,6 +90,7 @@ impl Printer { feature = "esp32c3", feature = "esp32c6", feature = "esp32h2", + feature = "esp32p4", feature = "esp32s3" ) ))] @@ -106,6 +107,11 @@ mod serial_jtag_printer { #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] const SERIAL_JTAG_CONF_REG: usize = 0x6000_F004; + #[cfg(feature = "esp32p4")] + const SERIAL_JTAG_FIFO_REG: usize = 0x500D_2000; + #[cfg(feature = "esp32p4")] + const SERIAL_JTAG_CONF_REG: usize = 0x500D_2004; + #[cfg(feature = "esp32s3")] const SERIAL_JTAG_FIFO_REG: usize = 0x6003_8000; #[cfg(feature = "esp32s3")] @@ -329,6 +335,23 @@ mod uart_printer { } } + #[cfg(feature = "esp32p4")] + impl Functions for Device { + const TX_ONE_CHAR: usize = 0x4FC0_0054; + + fn flush() { + unsafe { + const TX_FLUSH: usize = 0x4FC0_0074; + const GET_CHANNEL: usize = 0x4FC0_0038; + + let tx_flush: unsafe extern "C" fn(u8) = core::mem::transmute(TX_FLUSH); + let get_channel: unsafe extern "C" fn() -> u8 = core::mem::transmute(GET_CHANNEL); + + tx_flush(get_channel()); + } + } + } + impl super::Printer { pub fn write_bytes_assume_cs(&mut self, bytes: &[u8]) { for chunk in bytes.chunks(Device::CHUNK_SIZE) {