diff --git a/esp-hal-common/Cargo.toml b/esp-hal-common/Cargo.toml index a6e3a5ca7f..0f57b1bc42 100644 --- a/esp-hal-common/Cargo.toml +++ b/esp-hal-common/Cargo.toml @@ -160,6 +160,9 @@ rv-init-data = ["esp-riscv-rt/init-data", "esp-riscv-rt/init-rw-text"] rv-zero-rtc-bss = ["esp-riscv-rt/zero-rtc-fast-bss"] rv-init-rtc-data = ["esp-riscv-rt/init-rtc-fast-data", "esp-riscv-rt/init-rtc-fast-text"] +# Configuration for placing device drivers in the IRAM for faster access +optimize-spi-in-iram = [] + # Enable the `impl-register-debug` feature for the selected PAC debug = [ "esp32?/impl-register-debug", diff --git a/esp-hal-common/src/spi/master.rs b/esp-hal-common/src/spi/master.rs index cc0b82e4d3..51c912cb84 100644 --- a/esp-hal-common/src/spi/master.rs +++ b/esp-hal-common/src/spi/master.rs @@ -2527,7 +2527,7 @@ pub trait Instance { /// you must ensure that the whole messages was written correctly, use /// [`Self::flush`]. // FIXME: See below. - #[ram] + #[cfg_attr(feature = "optimize-spi-in-iram", ram)] fn write_bytes(&mut self, words: &[u8]) -> Result<(), Error> { let num_chunks = words.len() / FIFO_SIZE; @@ -2588,7 +2588,7 @@ pub trait Instance { /// Sends out a stuffing byte for every byte to read. This function doesn't /// perform flushing. If you want to read the response to something you /// have written before, consider using [`Self::transfer`] instead. - #[ram] + #[cfg_attr(feature = "optimize-spi-in-iram", ram)] fn read_bytes(&mut self, words: &mut [u8]) -> Result<(), Error> { let empty_array = [EMPTY_WRITE_PAD; FIFO_SIZE]; @@ -2609,7 +2609,7 @@ pub trait Instance { // FIXME: Using something like `core::slice::from_raw_parts` and // `copy_from_slice` on the receive registers works only for the esp32 and // esp32c3 varaints. The reason for this is unknown. - #[ram] + #[cfg_attr(feature = "optimize-spi-in-iram", ram)] fn read_bytes_from_fifo(&mut self, words: &mut [u8]) -> Result<(), Error> { let reg_block = self.register_block(); @@ -2646,7 +2646,7 @@ pub trait Instance { Ok(()) } - #[ram] + #[cfg_attr(feature = "optimize-spi-in-iram", ram)] fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Error> { for chunk in words.chunks_mut(FIFO_SIZE) { self.write_bytes(chunk)?;