Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serial: set active state level for RX and TX pins #203

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,20 @@
let ch = config.character_match.unwrap_or(0);
usart.cr2.write(|w| w.add().bits(ch));

// Set active state level for RX and TX pins
usart.cr2.modify(|_r, w| {
match config.active_level_tx {
ActiveLevel::Standard => w.txinv().clear_bit(),
ActiveLevel::Inverted => w.txinv().set_bit(),
};
match config.active_level_rx {
ActiveLevel::Standard => w.rxinv().clear_bit(),
ActiveLevel::Inverted => w.rxinv().set_bit(),
}
});

// Enable tx / rx, configure data bits and parity
usart.cr1.modify(|_, w| {

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f756, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f733, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f779, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f746, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f722, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f767, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f732, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f723, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f778, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f765, stable)

mismatched types

Check failure on line 203 in src/serial.rs

View workflow job for this annotation

GitHub Actions / ci (stm32f777, stable)

mismatched types
w.te().enabled().re().enabled().ue().enabled();

// M[1:0] are used to set data bits
// M[1:0] = 00: 1 Start bit, 8 data bits, n stop bits
// M[1:0] = 01: 1 Start bit, 9 data bits, n stop bits
Expand All @@ -205,7 +215,9 @@
Parity::ParityEven => w.ps().even().pce().enabled(),
Parity::ParityOdd => w.ps().odd().pce().enabled(),
Parity::ParityNone => w.pce().disabled(),
}
};

w.te().enabled().re().enabled().ue().enabled();
});

Check failure on line 221 in src/serial.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> src/serial.rs:203:33 | 203 | usart.cr1.modify(|_, w| { | _________________________________^ 204 | | // M[1:0] are used to set data bits 205 | | // M[1:0] = 00: 1 Start bit, 8 data bits, n stop bits 206 | | // M[1:0] = 01: 1 Start bit, 9 data bits, n stop bits ... | 220 | | w.te().enabled().re().enabled().ue().enabled(); 221 | | }); | |_________^ expected `&mut W<CR1_SPEC>`, found `()` | = note: expected mutable reference `&mut stm32f7::W<stm32f7::stm32f7x6::usart1::cr1::CR1_SPEC>` found unit type `()`

// Enable DMA
Expand Down Expand Up @@ -457,6 +469,16 @@
pub sysclock: bool,
pub parity: Parity,
pub data_bits: DataBits,
pub active_level_tx: ActiveLevel,
pub active_level_rx: ActiveLevel,
}

/// Active level on the wire
pub enum ActiveLevel {
/// Idle = high (VDD); Active = low (GND)
Standard,
/// Inverted: Idle = low (GND); Active = high (VDD)
Inverted,
}

pub enum Oversampling {
Expand Down Expand Up @@ -497,6 +519,8 @@
sysclock: false,
parity: Parity::ParityNone,
data_bits: DataBits::Bits8,
active_level_tx: ActiveLevel::Standard,
active_level_rx: ActiveLevel::Standard,
}
}
}
Expand Down Expand Up @@ -538,7 +562,7 @@
}
}

#[cfg(any(feature = "device-selected",))]

Check warning on line 565 in src/serial.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded sub `cfg` when there is only one condition

warning: unneeded sub `cfg` when there is only one condition --> src/serial.rs:565:7 | 565 | #[cfg(any(feature = "device-selected",))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `feature = "device-selected"` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg = note: `#[warn(clippy::non_minimal_cfg)]` on by default
impl_instance! {
USART1: (usart1sel),
USART2: (usart2sel),
Expand Down
Loading