Flush in spi::master::Instance::write before attemting any writes (#1381)

* Flush in `spi::master::Instancee::write` before attemting any writes

Otherwise subsequent calls to `SpiBus::write` will cause corrupted writes
and break `embedded-hal-bus`es transactions. Fixes #1369.

* Update Changelog for #1381

* Fix missing result handling when calling `flush()` in SPI `Instance::write_bytes`
This commit is contained in:
Markus Kasten 2024-04-03 02:55:40 +02:00 committed by GitHub
parent 55864b1ba7
commit 81a40703bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View File

@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- USB pullup/pulldown now gets properly cleared and does not interfere anymore on esp32c3 and esp32s3 (#1244)
- Fixed GPIO counts so that using async code with the higher GPIO number should no longer panic (#1361, #1362)
- ESP32/ESP32-S2: Wait for I2S getting out of TX_IDLE when starting a transfer (#1375)
- Fixed writes to SPI not flushing before attemting to write, causing corrupted writes (#1381)
### Changed

View File

@ -2618,6 +2618,10 @@ pub trait Instance: crate::private::Sealed {
fn write_bytes(&mut self, words: &[u8]) -> Result<(), Error> {
let num_chunks = words.len() / FIFO_SIZE;
// Flush in case previous writes have not completed yet, required as per
// embedded-hal documentation (#1369).
self.flush()?;
// The fifo has a limited fixed size, so the data must be chunked and then
// transmitted
for (i, chunk) in words.chunks(FIFO_SIZE).enumerate() {