Skip to content

Commit 1410d31

Browse files
authored
Merge pull request #317 from jr-oss/fix_uart_busy_handling
2 parents d30018e + 414f20e commit 1410d31

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
### Fixed
2222

2323
- Missing `MosiPin` impl for `PB5` ([#322])
24+
- Read valid data from data register even if reception of next character
25+
has started ([#317])
2426

2527
## [v0.9.0] - 2022-03-06
2628

@@ -562,6 +564,7 @@ let clocks = rcc
562564

563565
[#322]: https://github.com/stm32-rs/stm32f3xx-hal/pull/322
564566
[#318]: https://github.com/stm32-rs/stm32f3xx-hal/pull/318
567+
[#317]: https://github.com/stm32-rs/stm32f3xx-hal/pull/317
565568
[#314]: https://github.com/stm32-rs/stm32f3xx-hal/pull/314
566569
[#309]: https://github.com/stm32-rs/stm32f3xx-hal/pull/309
567570
[#308]: https://github.com/stm32-rs/stm32f3xx-hal/pull/308

src/adc/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use core::convert::TryFrom;
5050
/// [`Adc::set_pin_sequence_position`]: `super::Adc::set_pin_sequence_position`
5151
/// [`Adc::set_channel_sequence_position`]: `super::Adc::set_channel_sequence_position`
5252
/// [`Adc::channel_sequence`]: `super::Adc::channel_sequence`
53-
#[derive(Debug, PartialEq, PartialOrd, Copy, Clone)]
53+
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]
5454
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5555
#[allow(missing_docs)]
5656
pub enum Sequence {

src/serial.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,7 @@ where
881881
{
882882
let isr = usart.isr.read();
883883

884-
Err(if isr.busy().bit_is_set() {
885-
nb::Error::WouldBlock
886-
} else if isr.pe().bit_is_set() {
884+
Err(if isr.pe().bit_is_set() {
887885
usart.icr.write(|w| w.pecf().clear());
888886
nb::Error::Other(Error::Parity)
889887
} else if isr.fe().bit_is_set() {

src/serial/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::time::rate::{Baud, Extensions};
66
/// Stop Bit configuration parameter for serial.
77
///
88
/// Wrapper around [`STOP_A`]
9-
#[derive(Clone, Copy, Debug, PartialEq)]
9+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1010
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1111
pub enum StopBits {
1212
/// 0.5 stop bit
@@ -45,7 +45,7 @@ impl From<STOP_A> for StopBits {
4545
/// underlying USART will be configured to send/receive the parity bit in
4646
/// addtion to the data bits.
4747
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
48-
#[derive(Debug, Clone, Copy, PartialEq)]
48+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4949
pub enum Parity {
5050
/// No parity bit will be added/checked.
5151
None,
@@ -73,7 +73,7 @@ pub enum Parity {
7373
/// assert!(config.parity == Parity::None);
7474
/// assert!(config.stopbits == StopBits::STOP1);
7575
/// ```
76-
#[derive(Debug, Clone, Copy, PartialEq)]
76+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7777
#[non_exhaustive]
7878
pub struct Config {
7979
/// Serial interface baud rate

src/spi/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::time::rate::Generic;
3535
/// assert!(config.parity == Parity::None);
3636
/// assert!(config.stopbits == StopBits::STOP1);
3737
/// ```
38-
#[derive(Clone, Copy, PartialEq)]
38+
#[derive(Clone, Copy, PartialEq, Eq)]
3939
#[non_exhaustive]
4040
pub struct Config {
4141
/// Operating frequency of the SPI peripheral.

testsuite/tests/uart.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,30 @@ mod tests {
445445

446446
state.serial1 = Some(serial);
447447
}
448+
449+
#[test]
450+
fn test_busy_does_not_prevent_reading_data_register(state: &mut super::State) {
451+
let mut serial = state.serial1.take().unwrap();
452+
453+
while serial.is_busy() {}
454+
455+
let b1 = TEST_MSG[0];
456+
let b2 = TEST_MSG[1];
457+
458+
unwrap!(nb::block!(serial.write(b1)));
459+
while !serial.is_busy() {} // Wait until reception b1 started
460+
while serial.is_busy() {} // Wait until reception b1 complete
461+
unwrap!(nb::block!(serial.write(b2)));
462+
while !serial.is_busy() {} // Wait until reception b2 started
463+
464+
let c1 = unwrap!(nb::block!(serial.read())); // b1 in data register, b2 in shift register
465+
let c2 = unwrap!(nb::block!(serial.read())); // wait for b2 in data register
466+
467+
assert_eq!(b1, c1);
468+
assert_eq!(b2, c2);
469+
470+
state.serial1 = Some(serial);
471+
}
448472
}
449473

450474
// TODO: This maybe can be moved into a function inside the

0 commit comments

Comments
 (0)