Skip to content

Commit 8eb32db

Browse files
committed
fix USART2 remap, move tx & rx in Serial
1 parent bb24de6 commit 8eb32db

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030
- Add GPIOF/GPIOG support for high/xl density lines
3131

3232
### Fixed
33+
34+
- USART2 remap
3335
- Fix > 2 byte i2c reads
3436
- Send stop after acknowledge errors on i2c
3537
- Fix i2c interactions after errors
@@ -38,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3840

3941
### Changed
4042

43+
- Move Tx & Rx in Serial. `Read` and `Write` now implemented on `Rx` and `Tx`
4144
- USB driver is now enabled by default for all devices supporting it
4245
- Updated `bxcan` dependency
4346
- Change internal implementation of pins using const generics

src/serial.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Pins<USART2> for (PA2<Alternate<PushPull>>, PA3<Input<Floating>>) {
9999
}
100100

101101
impl Pins<USART2> for (PD5<Alternate<PushPull>>, PD6<Input<Floating>>) {
102-
const REMAP: u8 = 0;
102+
const REMAP: u8 = 1;
103103
}
104104

105105
impl Pins<USART3> for (PB10<Alternate<PushPull>>, PB11<Input<Floating>>) {
@@ -181,6 +181,8 @@ use crate::pac::usart1 as uart_base;
181181
pub struct Serial<USART, PINS> {
182182
usart: USART,
183183
pins: PINS,
184+
tx: Tx<USART>,
185+
rx: Rx<USART>,
184186
}
185187

186188
pub trait Instance:
@@ -315,7 +317,7 @@ where
315317
/// Separates the serial struct into separate channel objects for sending (Tx) and
316318
/// receiving (Rx)
317319
pub fn split(self) -> (Tx<USART>, Rx<USART>) {
318-
(Tx::new(), Rx::new())
320+
(self.tx, self.rx)
319321
}
320322
}
321323

@@ -365,7 +367,7 @@ macro_rules! hal {
365367
PINS: Pins<$USARTX>,
366368
{
367369
#[allow(unused_unsafe)]
368-
Serial { usart, pins }.init(config, clocks, || {
370+
Serial { usart, pins, tx: Tx::new(), rx: Rx::new() }.init(config, clocks, || {
369371
mapr.modify_mapr(|_, w| unsafe {
370372
#[allow(clippy::redundant_closure_call)]
371373
w.$usartX_remap().$bit(($closure)(PINS::REMAP))
@@ -506,7 +508,7 @@ where
506508
type Error = Error;
507509

508510
fn read(&mut self) -> nb::Result<u8, Error> {
509-
Rx::<USART>::new().read()
511+
self.rx.read()
510512
}
511513
}
512514

@@ -517,11 +519,11 @@ where
517519
type Error = Infallible;
518520

519521
fn flush(&mut self) -> nb::Result<(), Self::Error> {
520-
Tx::<USART>::new().flush()
522+
self.tx.flush()
521523
}
522524

523525
fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> {
524-
Tx::<USART>::new().write(byte)
526+
self.tx.write(byte)
525527
}
526528
}
527529

0 commit comments

Comments
 (0)