Skip to content

Commit 7cd25a5

Browse files
committed
A better fix and Change log update.
1 parent 2b27903 commit 7cd25a5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- move gpio, dma impls, adc pins in subdir, remove unused `From` impls [#658] [#664]
1313
- Bump `embedded-hal` to `1.0.0-alpha.10`. See [their changelog][embedded-hal-1.0.0-alpha.10] for further details. Note that this included breaking changes to the previous alpha APIs. [#663]
14+
- Fix race condition in sending start condition in I2C. [#662]
1415

1516
[#658]: https://github.com/stm32-rs/stm32f4xx-hal/pull/658
17+
[#662]: https://github.com/stm32-rs/stm32f4xx-hal/pull/662
1618
[#663]: https://github.com/stm32-rs/stm32f4xx-hal/pull/663
1719
[#664]: https://github.com/stm32-rs/stm32f4xx-hal/pull/664
1820
[embedded-hal-1.0.0-alpha.10]: https://github.com/rust-embedded/embedded-hal/blob/v1.0.0-alpha.10/embedded-hal/CHANGELOG.md

src/i2c/dma.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,15 @@ where
421421

422422
fn send_start(&mut self, read: bool) -> Result<(), super::Error> {
423423
let i2c = &self.hal_i2c.i2c;
424+
425+
// Make sure the ack and start bit is set together in a single
426+
// read-modify-write operation to avoid race condition.
427+
// See PR: https://github.com/stm32-rs/stm32f4xx-hal/pull/662
424428
if read {
425-
i2c.cr1.modify(|_, w| w.ack().set_bit());
429+
i2c.cr1.modify(|_, w| w.ack().set_bit().start().set_bit());
430+
} else {
431+
i2c.cr1.modify(|_, w| w.start().set_bit());
426432
}
427-
i2c.cr1.modify(|_, w| w.start().set_bit());
428433

429434
// Wait until START condition was generated
430435
while self

0 commit comments

Comments
 (0)