imxrt-rs/imxrt-hal

LPSPI transfer not reading data back into buffer

Closed this issue · 2 comments

We are currently having an issue where the LPSPI transfer reads no data back into the buffer. Our code worked fine with v0.4.2. Note that the SPI loopback example will obviously appear to work -- even if you disconnect sdo from sdi -- since the original output buffer is never written to.

Confirmed on a 1170EVK. Disconnecting the loopback in the hal_spi example should result in a data mismatch, observable through the console. But that doesn't happen. This issue doesn't affect the DMA SPI behavior; disconnecting the loopback results in the expected error.

The defect is due to how exchange interleaves transmit / receive actions. The MCU can enqueue all outgoing commands and data words before receiving any responses. Once there's no more data to transmit, it eagerly breaks the loop without reading any data.

The solution should be to introduce another loop that waits for all outstanding responses. But because the implementation uses continuous transactions, it re-exhibits this issue. I think there's a patch that forces the final receive word to manifest. I'll need some more time to test that or try other approaches.

The fix from #133 is in release 0.5.2.