Skip to content

Commit 4ed1629

Browse files
authored
Merge pull request #68 from gfroerli/serial-tx-rx-traits
Serial: Replace `Pins` trait with `TxPin` / `RxPin`
2 parents 6700dbc + 26bbfcf commit 4ed1629

File tree

9 files changed

+230
-86
lines changed

9 files changed

+230
-86
lines changed

Cargo.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ opt-level = "s"
264264

265265
[[example]]
266266
name = "adc_cont"
267-
required-features = ["stm32l0x2"]
267+
required-features = ["stm32l0x2", "io-STM32L071"]
268268

269269
[[example]]
270270
name = "adc_multi"
271-
required-features = ["stm32l0x2"]
271+
required-features = ["stm32l0x2", "io-STM32L071"]
272272

273273
[[example]]
274274
name = "adc_trig"
275-
required-features = ["stm32l0x2"]
275+
required-features = ["stm32l0x2", "io-STM32L071"]
276276

277277
[[example]]
278278
name = "aes_ecb"
@@ -312,15 +312,19 @@ required-features = ["rt","stm32l0x2"]
312312

313313
[[example]]
314314
name = "rtc"
315-
required-features = ["stm32l0x2"]
315+
required-features = ["stm32l0x2", "io-STM32L071"]
316+
317+
[[example]]
318+
name = "serial"
319+
required-features = ["stm32l0x2", "io-STM32L071"]
316320

317321
[[example]]
318322
name = "serial_dma"
319-
required-features = ["stm32l0x2"]
323+
required-features = ["stm32l0x2", "io-STM32L071"]
320324

321325
[[example]]
322326
name = "serial_dma_async"
323-
required-features = ["stm32l0x2"]
327+
required-features = ["stm32l0x2", "io-STM32L071"]
324328

325329
[[example]]
326330
name = "timer"

examples/rtc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ fn main() -> ! {
4545

4646
let serial = dp.USART2
4747
.usart(
48-
(gpioa.pa2, gpioa.pa3),
48+
gpioa.pa2,
49+
gpioa.pa3,
4950
serial::Config::default()
5051
.baudrate(115_200.bps()),
5152
&mut rcc,

examples/serial.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,14 @@ fn main() -> ! {
2222
// the RCC register.
2323
let gpioa = dp.GPIOA.split(&mut rcc);
2424

25-
#[cfg(feature = "stm32l0x1")]
26-
let tx_pin = gpioa.pa9;
27-
#[cfg(feature = "stm32l0x1")]
28-
let rx_pin = gpioa.pa10;
29-
30-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
31-
let tx_pin = gpioa.pa14;
32-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
33-
let rx_pin = gpioa.pa15;
25+
// Choose TX / RX pins
26+
let tx_pin = gpioa.pa2;
27+
let rx_pin = gpioa.pa3;
3428

3529
// Configure the serial peripheral.
3630
let serial = dp
3731
.USART2
38-
.usart((tx_pin, rx_pin), serial::Config::default(), &mut rcc)
32+
.usart(tx_pin, rx_pin, serial::Config::default(), &mut rcc)
3933
.unwrap();
4034

4135
let (mut tx, mut rx) = serial.split();

examples/serial_dma.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ fn main() -> ! {
4242
let (mut tx, mut rx) = dp
4343
.USART2
4444
.usart(
45-
(gpioa.pa2, gpioa.pa3),
45+
gpioa.pa2,
46+
gpioa.pa3,
4647
serial::Config::default().baudrate(115_200.bps()),
4748
&mut rcc,
4849
)

examples/serial_dma_async.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ fn main() -> ! {
4646
let gpioa = dp.GPIOA.split(&mut rcc);
4747

4848
let (tx, rx) = dp
49-
.USART2
50-
.usart(
51-
(gpioa.pa2, gpioa.pa3),
52-
serial::Config::default().baudrate(115_200.bps()),
53-
&mut rcc,
54-
)
55-
.unwrap()
56-
.split();
49+
.USART2
50+
.usart(
51+
gpioa.pa2,
52+
gpioa.pa3,
53+
serial::Config::default().baudrate(115_200.bps()),
54+
&mut rcc,
55+
)
56+
.unwrap()
57+
.split();
5758

5859
// we only have two elements for each queue, so U2 is fine (size is max 2)
5960
let mut rx_buffers: Queue<Pin<DmaBuffer>, U2> = Queue::new();

src/dma.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,29 @@ use crate::{
3535
I2C1,
3636
I2C2,
3737
I2C3,
38-
USART1,
39-
USART2,
4038
},
4139
rcc::Rcc,
42-
serial,
4340
};
4441

42+
#[cfg(any(feature = "io-STM32L051", feature = "io-STM32L071"))]
43+
use crate::pac::USART1;
44+
45+
#[cfg(any(
46+
feature = "io-STM32L021",
47+
feature = "io-STM32L031",
48+
feature = "io-STM32L051",
49+
feature = "io-STM32L071",
50+
))]
51+
use crate::pac::USART2;
52+
53+
#[cfg(any(
54+
feature = "io-STM32L021",
55+
feature = "io-STM32L031",
56+
feature = "io-STM32L051",
57+
feature = "io-STM32L071",
58+
))]
59+
use crate::serial;
60+
4561
#[cfg(feature = "stm32l082")]
4662
use crate::aes;
4763

@@ -521,13 +537,24 @@ impl_target!(
521537
// ADC
522538
adc::DmaToken, Channel1, 0;
523539
adc::DmaToken, Channel2, 0;
540+
);
524541

542+
#[cfg(any(feature = "io-STM32L051", feature = "io-STM32L071"))]
543+
impl_target!(
525544
// USART1
526545
serial::Tx<USART1>, Channel2, 3;
527546
serial::Tx<USART1>, Channel4, 3;
528547
serial::Rx<USART1>, Channel3, 3;
529548
serial::Rx<USART1>, Channel5, 3;
549+
);
530550

551+
#[cfg(any(
552+
feature = "io-STM32L021",
553+
feature = "io-STM32L031",
554+
feature = "io-STM32L051",
555+
feature = "io-STM32L071",
556+
))]
557+
impl_target!(
531558
// USART2
532559
serial::Tx<USART2>, Channel4, 4;
533560
serial::Tx<USART2>, Channel7, 4;

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ pub mod rcc;
3232
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
3333
pub mod rng;
3434
pub mod rtc;
35+
#[cfg(any(
36+
feature = "io-STM32L021",
37+
feature = "io-STM32L031",
38+
feature = "io-STM32L051",
39+
feature = "io-STM32L071",
40+
))]
3541
pub mod serial;
3642
pub mod spi;
3743
pub mod syscfg;

src/prelude.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ pub use crate::{
1616
i2c::I2cExt as _,
1717
pwr::PowerMode as _,
1818
rcc::RccExt as _,
19-
serial::{
20-
Serial1Ext as _,
21-
Serial2Ext as _,
22-
},
2319
spi::SpiExt as _,
2420
time::U32Ext as _,
2521
timer::TimerExt as _,
@@ -28,3 +24,26 @@ pub use crate::{
2824
WindowWatchdogExt as _,
2925
},
3026
};
27+
28+
#[cfg(any(
29+
feature = "io-STM32L021",
30+
feature = "io-STM32L031",
31+
feature = "io-STM32L051",
32+
feature = "io-STM32L071",
33+
))]
34+
pub use crate::serial::{
35+
Serial1LpExt as _,
36+
Serial2Ext as _,
37+
};
38+
#[cfg(any(
39+
feature = "io-STM32L051",
40+
feature = "io-STM32L071",
41+
))]
42+
pub use crate::serial::Serial1LpExt as _;
43+
#[cfg(any(
44+
feature = "io-STM32L071",
45+
))]
46+
pub use crate::serial::{
47+
Serial4Ext as _,
48+
Serial5Ext as _,
49+
};

0 commit comments

Comments
 (0)