Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QSPI #2013

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions esp-hal/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,12 @@ pub mod dma {
}

let result = unsafe {
self.spi
.start_write_bytes_dma(buffer.first(), bytes_to_write, &mut self.channel.tx)
self.spi.start_write_bytes_dma(
buffer.first(),
bytes_to_write,
&mut self.channel.tx,
true,
)
};
if let Err(e) = result {
return Err((e, self, buffer));
Expand All @@ -1346,8 +1350,12 @@ pub mod dma {
}

let result = unsafe {
self.spi
.start_read_bytes_dma(buffer.first(), bytes_to_read, &mut self.channel.rx)
self.spi.start_read_bytes_dma(
buffer.first(),
bytes_to_read,
&mut self.channel.rx,
true,
)
};
if let Err(e) = result {
return Err((e, self, buffer));
Expand Down Expand Up @@ -1481,8 +1489,12 @@ pub mod dma {
}

let result = unsafe {
self.spi
.start_read_bytes_dma(buffer.first(), bytes_to_read, &mut self.channel.rx)
self.spi.start_read_bytes_dma(
buffer.first(),
bytes_to_read,
&mut self.channel.rx,
false,
)
};
if let Err(e) = result {
return Err((e, self, buffer));
Expand Down Expand Up @@ -1559,8 +1571,12 @@ pub mod dma {
}

let result = unsafe {
self.spi
.start_write_bytes_dma(buffer.first(), bytes_to_write, &mut self.channel.tx)
self.spi.start_write_bytes_dma(
buffer.first(),
bytes_to_write,
&mut self.channel.tx,
false,
)
};
if let Err(e) = result {
return Err((e, self, buffer));
Expand Down Expand Up @@ -2261,16 +2277,19 @@ pub trait InstanceDma: Instance {
first_desc: *mut DmaDescriptor,
len: usize,
tx: &mut TX,
full_duplex: bool,
) -> Result<(), Error> {
let reg_block = self.register_block();
self.configure_datalen(len as u32 * 8);

tx.is_done();

// disable MISO and re-enable MOSI
reg_block
.user()
.modify(|_, w| w.usr_miso().bit(false).usr_mosi().bit(true));
// disable MISO and re-enable MOSI (DON'T do it for half-duplex)
if full_duplex {
reg_block
.user()
.modify(|_, w| w.usr_miso().bit(false).usr_mosi().bit(true));
}

self.enable_dma();
self.update();
Expand Down Expand Up @@ -2300,16 +2319,19 @@ pub trait InstanceDma: Instance {
desc: *mut DmaDescriptor,
data_length: usize,
rx: &mut RX,
full_duplex: bool,
) -> Result<(), Error> {
let reg_block = self.register_block();
self.configure_datalen(data_length as u32 * 8);

rx.is_done();

// re-enable MISO and disable MOSI
reg_block
.user()
.modify(|_, w| w.usr_miso().bit(true).usr_mosi().bit(false));
// re-enable MISO and disable MOSI (DON'T do it for half-duplex)
if full_duplex {
reg_block
.user()
.modify(|_, w| w.usr_miso().bit(true).usr_mosi().bit(false));
}

self.enable_dma();
self.update();
Expand Down