diff --git a/CHANGELOG.md b/CHANGELOG.md index e240dc899..0eb73c404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - DMA descriptor count no longer needs to be multiplied by 3 (#1054) - RMT channels no longer take the channel number as a generic param (#959) - The `esp-hal-common` package is now called `esp-hal` (#1131) +- Refactor the `Trace` driver to be generic around its peripheral (#1140) ### Removed diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index 1ddcd6e7d..975e3cffe 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -65,9 +65,9 @@ ufmt-write = { version = "0.1.0", optional = true } esp32 = { version = "0.28.0", features = ["critical-section"], optional = true } esp32c2 = { version = "0.17.0", features = ["critical-section"], optional = true } esp32c3 = { version = "0.20.0", features = ["critical-section"], optional = true } -esp32c6 = { version = "0.11.0", features = ["critical-section"], optional = true } -esp32h2 = { version = "0.7.0", features = ["critical-section"], optional = true } -esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "c801d10", optional = true } +esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a066f0e", features = ["critical-section"], optional = true } +esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a066f0e", features = ["critical-section"], optional = true } +esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "a066f0e", features = ["critical-section"], optional = true } esp32s2 = { version = "0.19.0", features = ["critical-section"], optional = true } esp32s3 = { version = "0.23.0", features = ["critical-section"], optional = true } diff --git a/esp-hal/devices/esp32c6/device.toml b/esp-hal/devices/esp32c6/device.toml index 42dd1ef7e..37ab80ba9 100644 --- a/esp-hal/devices/esp32c6/device.toml +++ b/esp-hal/devices/esp32c6/device.toml @@ -59,7 +59,7 @@ peripherals = [ "tee", "timg0", "timg1", - "trace", + "trace0", "twai0", "twai1", "uart0", diff --git a/esp-hal/devices/esp32h2/device.toml b/esp-hal/devices/esp32h2/device.toml index d31cc23e7..82d4770e2 100644 --- a/esp-hal/devices/esp32h2/device.toml +++ b/esp-hal/devices/esp32h2/device.toml @@ -52,7 +52,7 @@ peripherals = [ "tee", "timg0", "timg1", - "trace", + "trace0", # "twai0", "uart0", "uart1", diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 80eb5474f..bb0b8743a 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -146,7 +146,7 @@ pub mod system; pub mod systimer; #[cfg(any(timg0, timg1))] pub mod timer; -#[cfg(trace)] +#[cfg(trace0)] pub mod trace; #[cfg(any(twai0, twai1))] pub mod twai; diff --git a/esp-hal/src/soc/esp32c6/peripherals.rs b/esp-hal/src/soc/esp32c6/peripherals.rs index 7f23ecae7..c522f2eb5 100644 --- a/esp-hal/src/soc/esp32c6/peripherals.rs +++ b/esp-hal/src/soc/esp32c6/peripherals.rs @@ -78,7 +78,7 @@ crate::peripherals! { TEE <= TEE, TIMG0 <= TIMG0, TIMG1 <= TIMG1, - TRACE <= TRACE, + TRACE0 <= TRACE, TWAI0 <= TWAI0, TWAI1 <= TWAI1, UART0 <= UART0, diff --git a/esp-hal/src/soc/esp32h2/peripherals.rs b/esp-hal/src/soc/esp32h2/peripherals.rs index d9ce69e4c..daf2febb8 100644 --- a/esp-hal/src/soc/esp32h2/peripherals.rs +++ b/esp-hal/src/soc/esp32h2/peripherals.rs @@ -70,7 +70,7 @@ crate::peripherals! { TEE <= TEE, TIMG0 <= TIMG0, TIMG1 <= TIMG1, - TRACE <= TRACE, + TRACE0 <= TRACE, TWAI0 <= TWAI0, UART0 <= UART0, UART1 <= UART1, diff --git a/esp-hal/src/system.rs b/esp-hal/src/system.rs index 70abe155b..61b247224 100755 --- a/esp-hal/src/system.rs +++ b/esp-hal/src/system.rs @@ -101,8 +101,8 @@ pub enum Peripheral { Ecc, #[cfg(soc_etm)] Etm, - #[cfg(trace)] - Trace, + #[cfg(trace0)] + Trace0, #[cfg(lcd_cam)] LcdCam, } @@ -592,8 +592,8 @@ impl PeripheralClockControl { system.etm_conf().modify(|_, w| w.etm_clk_en().set_bit()); system.etm_conf().modify(|_, w| w.etm_rst_en().clear_bit()); } - #[cfg(trace)] - Peripheral::Trace => { + #[cfg(trace0)] + Peripheral::Trace0 => { system .trace_conf() .modify(|_, w| w.trace_clk_en().set_bit()); diff --git a/esp-hal/src/trace.rs b/esp-hal/src/trace.rs index 7cd6fcb53..75964f941 100644 --- a/esp-hal/src/trace.rs +++ b/esp-hal/src/trace.rs @@ -21,7 +21,7 @@ //! //! ## Example //! ```no_run -//! let mut trace = Trace::new(peripherals.TRACE); +//! let mut trace = Trace::new(peripherals.TRACE0); //! let buffer = unsafe { &mut BUFFER[..] }; //! trace.start_trace(buffer); //! // traced code @@ -33,6 +33,7 @@ use crate::{ peripheral::{Peripheral, PeripheralRef}, + peripherals::trace::RegisterBlock, system::PeripheralClockControl, }; @@ -50,17 +51,20 @@ pub struct TraceResult { } /// TRACE Encoder Instance -pub struct Trace<'d> { - peripheral: PeripheralRef<'d, crate::peripherals::TRACE>, +pub struct Trace<'d, T> { + peripheral: PeripheralRef<'d, T>, buffer: Option<&'d mut [u8]>, } -impl<'d> Trace<'d> { +impl<'d, T> Trace<'d, T> +where + T: Instance, +{ /// Construct a new instance - pub fn new(peripheral: impl Peripheral
+ 'd) -> Self { + pub fn new(peripheral: impl Peripheral
+ 'd) -> Self {
crate::into_ref!(peripheral);
- PeripheralClockControl::enable(crate::system::Peripheral::Trace);
+ PeripheralClockControl::enable(crate::system::Peripheral::Trace0);
Self {
peripheral,
@@ -70,29 +74,31 @@ impl<'d> Trace<'d> {
/// Start tracing, writing data into the `buffer`
pub fn start_trace(&mut self, buffer: &'d mut [u8]) {
- self.peripheral.mem_start_addr().modify(|_, w| {
- w.mem_staet_addr()
+ let reg_block = self.peripheral.register_block();
+
+ reg_block.mem_start_addr().modify(|_, w| {
+ w.mem_start_addr()
.variant(buffer.as_ptr() as *const _ as u32)
});
- self.peripheral.mem_end_addr().modify(|_, w| {
+ reg_block.mem_end_addr().modify(|_, w| {
w.mem_end_addr()
.variant((buffer.as_ptr() as *const _ as u32) + (buffer.len() as u32))
});
- self.peripheral
+ reg_block
.mem_addr_update()
.write(|w| w.mem_current_addr_update().set_bit());
// won't set bit in int-raw without enabling
- self.peripheral
+ reg_block
.intr_ena()
.modify(|_, w| w.mem_full_intr_ena().set_bit());
// for now always use looping mode
- self.peripheral
+ reg_block
.trigger()
.write(|w| w.mem_loop().set_bit().restart_ena().set_bit());
- self.peripheral.intr_clr().write(|w| {
+ reg_block.intr_clr().write(|w| {
w.fifo_overflow_intr_clr()
.set_bit()
.mem_full_intr_clr()
@@ -100,7 +106,7 @@ impl<'d> Trace<'d> {
});
self.buffer.replace(buffer);
- self.peripheral.trigger().write(|w| w.on().set_bit());
+ reg_block.trigger().write(|w| w.on().set_bit());
}
/// Stop tracing
@@ -108,7 +114,9 @@ impl<'d> Trace<'d> {
/// Be aware that valid data might not start at index 0 and you need to
/// account for wrapping when reading the data.
pub fn stop_trace(&mut self) -> Result