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

Should SPI read() send dummy data? #354

Closed
jgallagher opened this issue Jan 2, 2022 · 3 comments
Closed

Should SPI read() send dummy data? #354

jgallagher opened this issue Jan 2, 2022 · 3 comments
Labels
stm32 Has specific implications for STM32 processors

Comments

@jgallagher
Copy link
Contributor

jgallagher commented Jan 2, 2022

I've been working with a very finicky SPI device attached to an stm32f4, and copy-paste-modified my way from drv/stm32h7-spi-server to an SPI server driver for the stm32f4. I couldn't get read() to work though, and based on the comments in the changes in #351, I'm wondering if there's a bug in stm32h7-spi-server's read implementation. It passes None as the tx buffer:

self.ready_writey(SpiOperation::read, device_index, None, Some(dest))

which means ready_writey will never enter the block that transmits data (dummy or otherwise):

if let Some((tx_data, tx_pos)) = &mut tx {
while self.spi.can_tx_frame() {
// If our position is less than our tx len,
// transfer a byte from caller to TX FIFO --
// otherwise put a dummy byte on the wire
let byte: u8 = if *tx_pos < src_len {
tx_data
.read_at(usize::from(*tx_pos))
.ok_or(RequestError::went_away())?
} else {
0u8
};
ringbuf_entry!(Trace::Tx(*tx_pos, byte));
self.spi.send8(byte);
*tx_pos += 1;
made_progress = true;
// If we have _just_ finished...
if *tx_pos == src_len {
// We will finish transmitting well before
// we're done receiving, so stop getting
// interrupt notifications for transmit
// space available during that time.
self.spi.disable_can_tx_interrupt();
tx = None;
break;
}
}
}

I tested fixing this with a quick hack by adding an "else send dummy data" branch to that block, and it makes read() work for me. I doubt that's the best fix, but wanted to open this issue for awareness (or correction if I'm misreading/misunderstanding).

@cbiffle
Copy link
Collaborator

cbiffle commented Jan 5, 2022

Interesting -- the intent with read is that it shifts out dummy data. I'm not sure it's currently being exercised on our side, though. The STM32H7 SPI driver state machine has gotten a little...hairy over the past year or so and I could totally believe that there's a bug here.

@cbiffle cbiffle added the stm32 Has specific implications for STM32 processors label Jan 5, 2022
@cbiffle
Copy link
Collaborator

cbiffle commented Jan 22, 2022

@jgallagher you're spot on here, btw. I have a fix prepared (which also greatly improves SPI performance) but it's currently traffic jammed behind a few other of my pending PRs.

@cbiffle
Copy link
Collaborator

cbiffle commented Feb 2, 2022

This should be fixed on the stm32h7.

@cbiffle cbiffle closed this as completed Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stm32 Has specific implications for STM32 processors
Projects
None yet
Development

No branches or pull requests

2 participants