Skip to content

Commit ed8b0a2

Browse files
pftbestmvertescher
authored andcommitted
Add support for Error event and CharacterMatch event.
When chosen byte is received the hardware will generate CharacterMatch interrupt if enabled. Also allow to listen for error interrupts.
1 parent 2f7358d commit ed8b0a2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/serial.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ where
128128

129129
usart.brr.write(|w| unsafe { w.bits(brr) });
130130

131-
// Reset other registers to disable advanced USART features
132-
usart.cr2.reset();
131+
// Set character match and reset other registers to disable advanced USART features
132+
let ch = config.character_match.unwrap_or(0);
133+
usart.cr2.write(|w| w.add().bits(ch));
133134

134135
// Enable transmission and receiving
135136
usart
@@ -147,6 +148,8 @@ where
147148
match event {
148149
Event::Rxne => self.usart.cr1.modify(|_, w| w.rxneie().set_bit()),
149150
Event::Txe => self.usart.cr1.modify(|_, w| w.txeie().set_bit()),
151+
Event::CharacterMatch => self.usart.cr1.modify(|_, w| w.cmie().set_bit()),
152+
Event::Error => self.usart.cr3.modify(|_, w| w.eie().set_bit()),
150153
}
151154
}
152155

@@ -155,6 +158,8 @@ where
155158
match event {
156159
Event::Rxne => self.usart.cr1.modify(|_, w| w.rxneie().clear_bit()),
157160
Event::Txe => self.usart.cr1.modify(|_, w| w.txeie().clear_bit()),
161+
Event::CharacterMatch => self.usart.cr1.modify(|_, w| w.cmie().clear_bit()),
162+
Event::Error => self.usart.cr3.modify(|_, w| w.eie().clear_bit()),
158163
}
159164
}
160165

@@ -377,6 +382,7 @@ where
377382
pub struct Config {
378383
pub baud_rate: Bps,
379384
pub oversampling: Oversampling,
385+
pub character_match: Option<u8>,
380386
}
381387

382388
pub enum Oversampling {
@@ -389,6 +395,7 @@ impl Default for Config {
389395
Self {
390396
baud_rate: 115_200.bps(),
391397
oversampling: Oversampling::By16,
398+
character_match: None,
392399
}
393400
}
394401
}
@@ -400,6 +407,10 @@ pub enum Event {
400407
Rxne,
401408
/// New data can be sent
402409
Txe,
410+
/// Character match interrupt
411+
CharacterMatch,
412+
/// Error interrupt
413+
Error,
403414
}
404415

405416
/// Implemented by all USART instances

0 commit comments

Comments
 (0)