Skip to content

Commit 9321f0b

Browse files
committed
Serial: Implement UART peripherals based on device category
This requires setting an io-* Cargo feature in order to access the `serial` module.
1 parent d408ae7 commit 9321f0b

File tree

5 files changed

+73
-16
lines changed

5 files changed

+73
-16
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"

src/dma.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ use crate::{
3939
USART2,
4040
},
4141
rcc::Rcc,
42-
serial,
4342
};
4443

44+
#[cfg(any(
45+
feature = "io-STM32L021",
46+
feature = "io-STM32L031",
47+
feature = "io-STM32L051",
48+
feature = "io-STM32L071",
49+
))]
50+
use crate::serial;
51+
4552
#[cfg(feature = "stm32l082")]
4653
use crate::aes;
4754

@@ -521,13 +528,24 @@ impl_target!(
521528
// ADC
522529
adc::DmaToken, Channel1, 0;
523530
adc::DmaToken, Channel2, 0;
531+
);
524532

533+
#[cfg(any(feature = "io-STM32L051", feature = "io-STM32L071"))]
534+
impl_target!(
525535
// USART1
526536
serial::Tx<USART1>, Channel2, 3;
527537
serial::Tx<USART1>, Channel4, 3;
528538
serial::Rx<USART1>, Channel3, 3;
529539
serial::Rx<USART1>, Channel5, 3;
540+
);
530541

542+
#[cfg(any(
543+
feature = "io-STM32L021",
544+
feature = "io-STM32L031",
545+
feature = "io-STM32L051",
546+
feature = "io-STM32L071",
547+
))]
548+
impl_target!(
531549
// USART2
532550
serial::Tx<USART2>, Channel4, 4;
533551
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+
};

src/serial.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,17 +638,27 @@ macro_rules! usart {
638638
}
639639
}
640640

641-
#[cfg(feature = "stm32l0x1")]
641+
// LPUART1 and USART2 are available on category 1/2/3/5 MCUs
642+
#[cfg(any(
643+
feature = "io-STM32L021",
644+
feature = "io-STM32L031",
645+
feature = "io-STM32L051",
646+
feature = "io-STM32L071",
647+
))]
642648
usart! {
643-
LPUART1: (lpuart1, apb1enr, lpuart1en, apb1_clk, Serial1Ext),
649+
LPUART1: (lpuart1, apb1enr, lpuart1en, apb1_clk, Serial1LpExt),
644650
USART2: (usart2, apb1enr, usart2en, apb1_clk, Serial2Ext),
645651
}
646652

647-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
653+
// USART1 is available on category 3/5 MCUs
654+
#[cfg(any(feature = "io-STM32L051", feature = "io-STM32L071"))]
648655
usart! {
649-
LPUART1: (lpuart1, apb1enr, lpuart1en, apb1_clk, Serial1LpExt),
650656
USART1: (usart1, apb2enr, usart1en, apb1_clk, Serial1Ext),
651-
USART2: (usart2, apb1enr, usart2en, apb1_clk, Serial2Ext),
657+
}
658+
659+
// USART4 and USART5 are available on category 5 MCUs
660+
#[cfg(feature = "io-STM32L071")]
661+
usart! {
652662
USART4: (usart4, apb1enr, usart4en, apb1_clk, Serial4Ext),
653663
USART5: (usart5, apb1enr, usart5en, apb1_clk, Serial5Ext),
654664
}

0 commit comments

Comments
 (0)