Skip to content

Commit 4352ea8

Browse files
authored
Enable DMA for USART on STM32F302 devices (#139)
authored-by: sprhawk <465558+sprhawk@users.noreply.github.com>
1 parent 788aedb commit 4352ea8

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- SPI support for reclock after initialization ([#98](https://github.com/stm32-rs/stm32f3xx-hal/pull/98))
1414
- Support for `stm32f302x6` and `stm32f302x8` devices ([#132](https://github.com/stm32-rs/stm32f3xx-hal/pull/132))
1515
- Support for the onboard real-time clock (RTC) ([#136](https://github.com/stm32-rs/stm32f3xx-hal/pull/136))
16+
- Enable DMA for USART on `stm32f302` devices ([#139](https://github.com/stm32-rs/stm32f3xx-hal/pull/139))
1617

1718
## [v0.5.0] - 2020-07-21
1819

src/dma.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,14 @@ dma!(
494494
);
495495

496496
#[cfg(any(
497+
feature = "stm32f302xb",
498+
feature = "stm32f302xc",
499+
feature = "stm32f302xd",
500+
feature = "stm32f302xe",
497501
feature = "stm32f303xb",
498502
feature = "stm32f303xc",
499503
feature = "stm32f303xd",
500-
feature = "stm32f303xe"
504+
feature = "stm32f303xe",
501505
))]
502506
dma!(
503507
DMA2, dma2, dma2en,
@@ -527,7 +531,6 @@ macro_rules! on_channel {
527531
};
528532
}
529533

530-
#[cfg(feature = "stm32f303")]
531534
on_channel!(dma1,
532535
serial::Rx<pac::USART1> => C5,
533536
serial::Tx<pac::USART1> => C4,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub use crate::pac::interrupt;
116116
pub mod adc;
117117
#[cfg(feature = "device-selected")]
118118
pub mod delay;
119-
#[cfg(feature = "stm32f303")]
119+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
120120
pub mod dma;
121121
#[cfg(feature = "device-selected")]
122122
pub mod flash;

src/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Prelude
22
3-
#[cfg(feature = "stm32f303")]
3+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
44
pub use crate::dma::DmaExt as _stm32f3xx_hal_dma_DmaExt;
55
pub use crate::flash::FlashExt as _stm32f3xx_hal_flash_FlashExt;
66
pub use crate::gpio::GpioExt as _stm32f3xx_hal_gpio_GpioExt;

src/serial.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ use crate::gpio::gpiod;
3737
))]
3838
use crate::gpio::gpioe;
3939

40-
#[cfg(feature = "stm32f303")]
40+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
4141
use crate::dma;
42-
#[cfg(feature = "stm32f303")]
42+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
4343
use cortex_m::interrupt;
4444

4545
/// Interrupt event
@@ -363,7 +363,7 @@ macro_rules! hal {
363363

364364
impl blocking::serial::write::Default<u8> for Tx<$USARTX> {}
365365

366-
#[cfg(feature = "stm32f303")]
366+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
367367
impl Rx<$USARTX> {
368368
/// Fill the buffer with received data using DMA.
369369
pub fn read_exact<B, C>(
@@ -384,7 +384,7 @@ macro_rules! hal {
384384
}
385385
}
386386

387-
#[cfg(feature = "stm32f303")]
387+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
388388
impl Tx<$USARTX> {
389389
/// Transmit all data in the buffer using DMA.
390390
pub fn write_all<B, C>(
@@ -405,7 +405,7 @@ macro_rules! hal {
405405
}
406406
}
407407

408-
#[cfg(feature = "stm32f303")]
408+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
409409
impl dma::Target for Rx<$USARTX> {
410410
fn enable_dma(&mut self) {
411411
// NOTE(unsafe) critical section prevents races
@@ -424,7 +424,7 @@ macro_rules! hal {
424424
}
425425
}
426426

427-
#[cfg(feature = "stm32f303")]
427+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
428428
impl dma::Target for Tx<$USARTX> {
429429
fn enable_dma(&mut self) {
430430
// NOTE(unsafe) critical section prevents races
@@ -446,24 +446,8 @@ macro_rules! hal {
446446
}
447447
}
448448

449-
#[cfg(any(
450-
feature = "stm32f301",
451-
feature = "stm32f318",
452-
feature = "stm32f303",
453-
feature = "stm32f373",
454-
feature = "stm32f378",
455-
feature = "stm32f328",
456-
feature = "stm32f358",
457-
feature = "stm32f398"
458-
))]
459449
hal! {
460450
USART1: (usart1, APB2, usart1en, usart1rst, pclk2),
461451
USART2: (usart2, APB1, usart2en, usart2rst, pclk1),
462452
USART3: (usart3, APB1, usart3en, usart3rst, pclk1),
463453
}
464-
465-
#[cfg(any(feature = "stm32f302", feature = "stm32f334"))]
466-
hal! {
467-
USART1: (usart1, APB2, usart1en, usart1rst, pclk2),
468-
USART2: (usart2, APB1, usart2en, usart2rst, pclk1),
469-
}

0 commit comments

Comments
 (0)