Skip to content

Commit

Permalink
SPI in IRAM
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfFan committed Jan 19, 2024
1 parent ff963dc commit fef48ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions esp-hal-common/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];

Expand All @@ -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();

Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit fef48ec

Please sign in to comment.