stm32_common/spi: fix receive after transmit-only error #6764
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This line fixes SPI transmissions on at least the faster class of stm32 devices.
The main problem is that there is a slight delay between the SPI transfer register being written and the BUSY bit being set. From the datasheet of the stm32f405..439 (20MB warning)
With this delay, after a write only operation, it is possible that the RXNE bit is checked while the data has not yet been received. If a read/write SPI transfer happens next, the old receive data is read.
As adviced by the datasheet, this patch inserts a TXE check in the write only path of the SPI code. A different solution might be to wait until the RXNE bit is set before reading the DR register, but this solution is not explicitly advised by the datasheet.
I only had time to check this solution on the stm32f4discovery board. I'm interested whether this patch breaks anything on the slower class of stm32 devices.
fixes #6519
And I'm curious to know if this also fixes #6750
All credits to @phectori for digging around in the datasheets :)